none
error LNK2001: unresolved external symbol

    Question

  • 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. 
    Friday, July 03, 2009 8:06 AM

Answers

  • If the GABaseSolver::operator() should override the virtual Selector::operator(), then it has to have the same type of arguments.

    Friday, July 03, 2009 12:02 PM

All replies

  • You need an implementation for the operator () in the Selector class.
    If not make it pure virtual.
    virtual int operator()(vector<GA1DArraySolution*>*, vector<GA1DArraySolution*>*) = 0;

    «_Superman_»
    Friday, July 03, 2009 9:02 AM
  • The linker tells you that it can't find the code for Selector::operator().  I can't find it either, it is not in your code snippet.  Did you forget to write it?

    Hans Passant.
    Friday, July 03, 2009 11:25 AM
  • I got the code from somewhr. The problem is that selector is just meant to be abstract, so that myrankingselector can be derived from it and then used. so i don't know what to write in the operator() for selector.

    if i make it pure virtual, i get the following msg:

    error C2259: 'GABaseSolver::MyRankingSelector' : cannot instantiate abstract class
            due to following members:
            'int Selector::operator ()(std::vector<_Ty> *,std::vector<_Ty> *)' : is abstract
            with
            [
                _Ty=GA1DArraySolution *
            ]
            d:\som\somyasinha\CommonBase.h(29) : see declaration of 'Selector::operator ()'

    thanks for the help.
    Friday, July 03, 2009 12:01 PM
  • If the GABaseSolver::operator() should override the virtual Selector::operator(), then it has to have the same type of arguments.

    Friday, July 03, 2009 12:02 PM
  • Thanks! I made the argument list the same. It's ok now.
    Friday, July 03, 2009 12:18 PM