Thread: Abstract class de/con-structor problem

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    Question Abstract class de/con-structor problem

    Hi all,

    I have tried to make an abstract class in the file Cat.h that already contains the class Cat, but I cant get the Cat class to extend the Abstract cat class. My goal is to make an interface for the Cat class.
    Cat.h:
    Code:
    /**
    Enumerator for cat object types
    */
    typedef enum {
      cob_Male, 
      cob_Female, 
      cob_NeuMale, 
      cob_NeuFemale
    } Cat_Object;
    	
    typedef enum
    {
          Cat_InitialState,
          Cat_Movement,
    	  Cat_ReproBehaviour
    } TypeOfCatState;
    
    class Abstract_Cat : public TAnimal
    {
    public:
    	Abstract_Cat();
    	virtual	~Abstract_Cat();
    
    	virtual void BeginStep       (void) = 0;
                    ...
    	virtual int EvaluateBestDirection() = 0;
    };
    
    class Cat : public Abstract_Cat
    {
    public:
    	Cat(int a_x, int a_y, Landscape * p_L, Cat_Population_Manager* p_PPM);
    	virtual ~Cat(void);
    
    protected:
    	//variables
    	Cat_Population_Manager* m_OurPopulationManager;
    	...
    	int StepsSoFarWithoutGoingHome;
    	TypeOfCatState m_CurrentCState;
    	
    	//lists
    	int QualityScoreArray[8]; //array for keeping the score values for each direction (0-7) - method:EvaluateBestDirection()
    	vector<int> BestDirectionsList; //list for holding directions with the highest score
    	
    	//methods
    	virtual void BeginStep       (void);
                    ...
    	int EvaluateBestDirection();
    };
    
    class struct_Cat
    {
    	public:	
    		int x;
    		int y;
    		Landscape* L;
    		Cat_Population_Manager* CM;	
    };
    Error:
    1>Cat.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Abstract_Cat::~Abstract_Cat(void)" (??1Abstract_Cat@@UAE@XZ) referenced in function "public: virtual __thiscall Cat::~Cat(void)" (??1Cat@@UAE@XZ)
    1>Cat.obj : error LNK2019: unresolved external symbol "public: __thiscall Abstract_Cat::Abstract_Cat(void)" (??0Abstract_Cat@@QAE@XZ) referenced in function "public: __thiscall Cat::Cat(int,int,class Landscape *,class Cat_Population_Manager *)" (??0Cat@@QAE@HHPAVLandscape@@PAVCat_Population_Man ager@@@Z)
    1>.\vc_mswd\almass.exe : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    And if i remove the constructor in class Abstract_Cat (Abstract_Cat()) then i get an error message that says a cannot instantiate objects of an abstract class.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You need to implement the constructors and destructors for Abstract_Cat, not just declare them.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I also don't see a declaration for TAnimal.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Thank you, i just added this part to Cat.cpp and it works.
    Code:
    Abstract_Cat::Abstract_Cat(int a_x, int a_y, Landscape * p_L, Cat_Population_Manager* p_PPM) : TAnimal(a_x,a_y,p_L)
    {
    }
    
    Abstract_Cat::~Abstract_Cat()
    {
    }
    thanks a lot :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-04-2011, 12:40 AM
  2. Question about design class..
    By ovid in forum C++ Programming
    Replies: 5
    Last Post: 03-17-2010, 10:34 AM
  3. abstract class member cannot be overladed?
    By dudeomanodude in forum C++ Programming
    Replies: 10
    Last Post: 12-10-2008, 11:12 AM
  4. Abstract Base Class and References
    By Thantos in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2004, 01:35 PM