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. C / C++ / MFC
  4. virtual destructor

virtual destructor

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 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.
  • L Offline
    L Offline
    lavate malllik
    wrote on last edited by
    #1

    Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye

    T T H 3 Replies Last reply
    0
    • L lavate malllik

      Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      lavate malllik wrote:

      can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class.

      try http://www.parashift.com[^]

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY-

      L 1 Reply Last reply
      0
      • L lavate malllik

        Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        you write a destructor to deallocate te memory allocated dynamically during the object's life (from construction to now - destruction). the fact a destructor is virtual or not is a matter of inheritence and doesn't affect what you write in the destructor body. and to call the destructor, you don't have to do anything much. an object is automattically when the execution goes out of the scope of the object.


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        L 1 Reply Last reply
        0
        • L lavate malllik

          Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Seehttp://new-brunswick.net/workshop/c++/faq/virtual-functions.html[^] if its good for you

          _**


          **_

          WhiteSky


          1 Reply Last reply
          0
          • T ThatsAlok

            lavate malllik wrote:

            can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class.

            try http://www.parashift.com[^]

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY-

            L Offline
            L Offline
            lavate malllik
            wrote on last edited by
            #5

            thanks for reply.. can u give me a piece of code where it shows it has written something in destructor...? i wnat to knwo what we have to write in a destructor of base & derived class when base class destructor is virtual? are we have to write any thing is any one of destructor?

            1 Reply Last reply
            0
            • T toxcct

              you write a destructor to deallocate te memory allocated dynamically during the object's life (from construction to now - destruction). the fact a destructor is virtual or not is a matter of inheritence and doesn't affect what you write in the destructor body. and to call the destructor, you don't have to do anything much. an object is automattically when the execution goes out of the scope of the object.


              TOXCCT >>> GEII power

              [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

              L Offline
              L Offline
              lavate malllik
              wrote on last edited by
              #6

              SAY if my destructor body is empty & I call delete p.it will call destructor & ultimately it will destroy the object of base & derived irrespective of empty body of destructor....

              Z 1 Reply Last reply
              0
              • L lavate malllik

                SAY if my destructor body is empty & I call delete p.it will call destructor & ultimately it will destroy the object of base & derived irrespective of empty body of destructor....

                Z Offline
                Z Offline
                Zac Howland
                wrote on last edited by
                #7

                Here is a very simple illustration on how they work:

                class Base
                {
                public:
                	Base()			{ cout << "Base::Base()" << endl; }
                	virtual ~Base()		{ cout << "Base::~Base()" << endl; }
                };
                
                class Derived : public Base
                {
                public:
                	Derived()		{ cout << "Derived::Derived()" << endl; }
                	virtual ~Derived()	{ cout << "Derived::~Derived()" << endl; }
                };
                
                void main()
                {
                	Base b;
                	Derived d;
                }
                

                Output: Base::Base() Base::Base() Derived::Derived() Derived::~Derived() Base::~Base() Base::~Base()

                If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                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