error LNK2001: unresolved external symbol

Hi,

I am using Visual C++ 2008 Express Edition. I define a class Selector in one header file.

class Selector : public UOFId
{
public:

virtual int operator()(vector<GA1DArraySolution*>*, vector<GA1DArraySolution*>*);
};

In another class "GABaseSolver", I have a member "MyRankingSelector" (which is a class derived from class "Selector"). I also initialize this in the constructor for GABaseSolver.

class GABaseSolver: public PopBaseSolver
{
public:
Selector *m_pSlct;

virtual void SetSelector(Selector *s){m_pSlct = s;}

class MyRankingSelector : public Selector
{
public:
int operator()(vector<GA1DArraySolution*> &src, vector<GA1DArraySolution*> &result);
};
};


GABaseSolver::GABaseSolver(PopSolution& src,size_t size): PopBaseSolver()
{
//some code

static MyRankingSelector rs;
m_pSlct = &rs;
}

The problem is that m_pSlct is pointer to Selector, and ultimately, I want to use it as pointer to MyRankingSelector, because I want to use operator () defined in MyRankingSelector.

The code gets compiled. On linking, I get the error:

GABaseSolver.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Selector::operator()(class std::vector<class GA1DArraySolution *,class std::allocator<class GA1DArraySolution *> > *,class std::vector<class GA1DArraySolution *,class std::allocator<class GA1DArraySolution *> > *)" (??RSelector@@UAEHPAV?$vector@PAVGA1DArraySolution @@V?$allocator@PAVGA1DArraySolution@@@std@@@std@@0 @Z)
D:\Som\Debug\SomyaSinha.exe : fatal error LNK1120: 1 unresolved externals


Please help. I hope I have been clear in explaining the problem.
"unresolved external symbol" means the linker can't find the body for that function. This is usually because you never gave the function a body.

1
2
3
4
5
6
class Selector : public UOFId
{
public:

virtual int operator()(vector<GA1DArraySolution*>*, vector<GA1DArraySolution*>*);  // <--- this function has no body
};


Make sure you give that function a body. If that class is supposed to be abstract, and the function is never to have its own body, then you can make the function pure virtual instead:

 
virtual int operator()(vector<GA1DArraySolution*>*, vector<GA1DArraySolution*>*) = 0;  //  = 0 to make it pure virtual 
Last edited on
Topic archived. No new replies allowed.