Connecting Tech Pros Worldwide Help | Site Map

error LNK2001: unresolved external symbol

  #1  
Old July 3rd, 2009, 08:53 AM
Newbie
 
Join Date: Jul 2009
Posts: 1
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.
  #2  
Old July 6th, 2009, 05:04 PM
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,338

re: error LNK2001: unresolved external symbol


Your code is compiling OK. However, the linker can't find your
Selector::operator() member function.

I realize that at run-time you will have another type for m_pSlct but as written your need a Selector::operator() for the link to succeed. This may the case where you need a pure virtual function for Selector::operator().
Reply

Tags
error lnk2001, external symbol, unresolved externals


Similar Threads
Thread Thread Starter Forum Replies Last Post
error LNK2001: Unresolved external symbol bonnielym84 answers 5 May 18th, 2007 07:49 AM
error LNK2001: unresolved external symbol sadegh answers 6 April 17th, 2007 10:55 AM
error LNK2001: unresolved external symbol sadegh answers 1 April 16th, 2007 05:25 PM
error LNK2001: unresolved external symbol ozgan.net answers 2 July 22nd, 2005 06:19 PM
error LNK2001: unresolved external symbol - Ultra noob question We need more power captain answers 3 July 22nd, 2005 07:40 AM