CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    70

    [RESOLVED] Linker Error

    Hello all, i would appreciate it if anyone could enlighten me on a linker error.

    First off the error
    Code:
    Error	1	error LNK2019: unresolved external symbol "public: __thiscall ReachTop<class Character>::ReachTop<class Character>(class Character *)" (??0?$ReachTop@VCharacter@@@@QAE@PAVCharacter@@@Z) referenced in function "void __cdecl `dynamic initializer for 'gReachTop''(void)" (??__EgReachTop@@YAXXZ)	Main.obj	DecisionTest

    Reach Top class inherits from Goal Class

    Goal Class
    Code:
    #ifndef _GOAL_H
    #define _GOAL_H
    
    #include "Action.h"
    #include <list>
    
    template <class T>
    class Goal
    {
    public:
    	Goal(T* pOwner) : mpOwner(pOwner) {}
    	virtual ~Goal() {}
    	
    	virtual float CalculateDesirability() = 0;
    	virtual Action<T>* CreateAction() = 0;
    
    protected:
    	T* mpOwner;
    };
    
    template <class T>
    struct GoalList
    {
    	typedef std::list<Goal<T>*> Type;
    };
    
    #endif
    ReachTop Class Header
    Code:
    #ifndef _REACHTOP_H
    #define _REACHTOP_H
    
    #include <AI.h>
    #include <SGE.h>
    
    using namespace SGE;
    
    template <typename T>
    class ReachTop : public Goal<T>
    {
    public:
    	ReachTop<T>(T* pOwner);
    	virtual ~ReachTop() {}
    	
    	virtual float CalculateDesirability();
    	virtual Action<T>* CreateAction();
    
    protected:
    	T* mpOwner;
    };
    
    
    #endif
    Reachtop class cpp
    Code:
    #include "ReachTop.h"
    
    
    template <typename T>
    ReachTop<T>::ReachTop(T* pOwner) 
    : mpOwner(pOwner)
    {
    
    }
    
    template <typename T>
    float ReachTop<T>::CalculateDesirability()
    {
    
    }
    
    template <typename T>
    Action<T>* ReachTop<T>::CreateAction()
    {
    
    }
    Code to create
    Code:
    Character* gCharacter = new Character(1, gWorld);
    Goal<Character>* gReachTop = new ReachTop<Character>(gCharacter);
    Any ideas? I can provide the character class and its inheritance aswell if you like.
    Last edited by marsh; December 10th, 2012 at 02:34 PM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Linker Error


  3. #3
    Join Date
    Sep 2008
    Posts
    70

    Re: Linker Error

    I tried a inline file before and i just got

    Code:
     error C2512: 'Goal<T>' : no appropriate default constructor available
    1>        with
    1>        [
    1>            T=Character
    1>        ]
    1>       *\reachtop.h(13) : while compiling class template member function 'ReachTop<T>::ReachTop(T *)'
    1>        with
    1>        [
    1>            T=Character
    1>        ]
    1>        *\main.cpp(14) : see reference to class template instantiation 'ReachTop<T>' being compiled
    1>        with
    1>        [
    1>            T=Character
    1>        ]
    instead

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Linker Error

    C2512 Since you've provided a constructor that takes a parameter, you must provide a default constructor as well (a constructor taking no parameters). The compiler will not automatically create one in these cases.

    Viggy

  5. #5
    Join Date
    Sep 2008
    Posts
    70

    Re: Linker Error

    I tried providing that already aswell. Same error.

    [Edit]

    Nevermind i added one to goal aswell and it fixed it. Thank you both.
    Last edited by marsh; December 10th, 2012 at 03:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured