a link error
-
I create an abstract class and a class derived from it. I know that an abstract class's object cannot be created until all its pure virtual functions are redefined within their derived class. However, How about the constructor and destructor functions? As they are special class functions, they can not be redefined within their derived class. class Abstract_base { public: virtual ~Abstract_base()=0; virtual void interface1() const = 0; virtual const char* mumber() const { return _mumble; }; protected: char *_mumble; }; class Concrete_derived : public Abstract_base { public: Concrete_derived() { }; virtual void interface1() const {}; }; int main { Concrete_derived trouble; return 0; } The code above has link eror.(error LNK2019) If I change "virtual ~Abstract_base()=0;" to "virtual ~Abstract_base()=0; {}", the link error disappeared. Why shall we add "virtual" to the destructor function? Can you give me some explanation? My thanks
-
I create an abstract class and a class derived from it. I know that an abstract class's object cannot be created until all its pure virtual functions are redefined within their derived class. However, How about the constructor and destructor functions? As they are special class functions, they can not be redefined within their derived class. class Abstract_base { public: virtual ~Abstract_base()=0; virtual void interface1() const = 0; virtual const char* mumber() const { return _mumble; }; protected: char *_mumble; }; class Concrete_derived : public Abstract_base { public: Concrete_derived() { }; virtual void interface1() const {}; }; int main { Concrete_derived trouble; return 0; } The code above has link eror.(error LNK2019) If I change "virtual ~Abstract_base()=0;" to "virtual ~Abstract_base()=0; {}", the link error disappeared. Why shall we add "virtual" to the destructor function? Can you give me some explanation? My thanks
I suggest asking in the right forum ( visual C++ is for non-.NET C++ )
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
-
I suggest asking in the right forum ( visual C++ is for non-.NET C++ )
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )