I am defining the below function in order to calculate combinations .... it works fine on borland... but when i run it on vc++ 6.0, it generates the
error

"error LNK2001: unresolved external symbol "public: void __thiscall bruteFrce::generate_combination(int)" (?generate_combination@bruteFrce@@QAEXH@Z)
Debug/AlgoProject.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe."

i have included the following classes in my code...

#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "stdafx.h"
#include "AlgoProject.h"
#include "bruteFrce.h"
#include "time.h"
#include "iostream.h"

and the function is :

void generate_combination (int tasks)
{

unsigned int max_mask_length;
unsigned int mask;
int s_pos,c_pos=0;

unsigned int comb_mask = 0x00000001;
char source_string[MAX];
char combination_string[MAX];

int len, lencomb;
int m,n=0;
char** combinations = new char*[200];
for(int j=0; j<200; j++)
  combinations[j] = new char [50];
for (int i=0; i<tasks; i++)
    source_string[i]= i;
len = strlen (source_string);
  max_mask_length = ~(0x00000001 << len);
 while (1)
    {
        mask = 0x00000001;
        s_pos = 0, c_pos = 0;
         while ((mask & max_mask_length))
        {
          if ((comb_mask & mask))
          {
              combination_string[c_pos] = source_string[s_pos];
              c_pos++;
          }
          s_pos++;
          mask <<= 1;
        }
combination_string[c_pos] = 0;
lencomb = strlen (combination_string);
for (int k=0 ;k< lencomb ; k++)
 combinations[m][k] =  combination_string[k];
m++;
if (c_pos ==0)
  break;

else
  continue;
    }
}

kindly guide me which library or class am i missing,,, ?? or is there any other reason for the error...

Dani AI

Generated

As suggested, the linker message points to a missing member-definition: the class declares a method but the linker cannot find the class-scoped implementation. The most common cause is defining the function as a free function instead of as a member of the class (or having a signature mismatch). The correct pattern is to match the declaration exactly and use the scope resolution operator in the .cpp file, for example:

// bruteFrce.h
class bruteFrce {
public:
    void generate_combination(int tasks);
};
// bruteFrce.cpp
#include "bruteFrce.h"

void bruteFrce::generate_combination(int tasks)
{
    // implementation
}

Checklist to resolve the LNK2001 in MSVC:

  • Confirm the prototype in bruteFrce.h matches the definition exactly (parameter types, const/ref qualifiers, namespace, and spelling of the class and method). Any difference produces a differently-mangled symbol.
  • Make sure the .cpp file that contains the definition is actually part of the VC++ project and being compiled (add the file to the project and do a full Rebuild All).
  • If the method was declared static or inline in the class, define it appropriately: static members still use bruteFrce:: in the definition; inline/template implementations generally belong in the header.
  • Check for calling-convention or linkage changes (extern "C", __stdcall, mismatched compiler toolchains) — these change the symbol names.

Separate note on the implementation: storing raw small integers in char buffers and calling C-string functions like strlen without a terminating NUL can cause undefined behavior at runtime. Consider using std::string or std::vector<int> for source/combination storage and ensure buffers are null-terminated before calling string routines.

Applying the scope-resolution fix and verifying the implementation file is compiled by the project will resolve the unresolved external in almost every case.

Should generate_combination() be an operation of the class bruteFrce? Like void bruteFrce::generate_combination(int) or should it really be outside the scope of the class bruteFrce?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.