Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. a link error

a link error

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richardye
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • R richardye

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      R 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        R Offline
        R Offline
        richardye
        wrote on last edited by
        #3

        I have thought that question for visual C++ might be something like MFC ,not pure C++ questions. Thank you for your suggestion. I will ask the same question in Visual C++ forum. Tommorow is another day

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups