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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS

COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 5 Posters 1 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.
  • S Offline
    S Offline
    Subramaniam s V
    wrote on last edited by
    #1

    can anyone help me out in clearly understanding the concept of COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. I have gone through lots of books but still i am not much clear as why we go for COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. Kindly help me out.

    N T _ H 4 Replies Last reply
    0
    • S Subramaniam s V

      can anyone help me out in clearly understanding the concept of COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. I have gone through lots of books but still i am not much clear as why we go for COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. Kindly help me out.

      N Offline
      N Offline
      Nyarlatotep
      wrote on last edited by
      #2

      Virtual destructors have the same meaning of virtual methods. Those are useful if you use a base class pointer to hold a derived class pointer. if base class destructor is not virtual : class A { public: ~A() { cout << "Class A destructor"; } }; class B : public A { public: ~B() { cout << "Class B destructor"; } }; B *Bobj = new B; A *Aobj = Bobj; delete Aobj; Only the A destructor is invoked. if you make A destructor Virtual, the destructors of derived class and base class (in this order) are invoked. Copy constructors are used to copy an object, in these cases: MyClass obj; MyClass obj2(obj); // Copy constructor invoked MyClass obj = obj2; // Copy construcotr invoked obj = obj2, in this case the assignment operator is used ...

      1 Reply Last reply
      0
      • S Subramaniam s V

        can anyone help me out in clearly understanding the concept of COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. I have gone through lots of books but still i am not much clear as why we go for COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. Kindly help me out.

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

        copy constructor have an explicit enough name ! it gets another instance of its class, and duplicate it into "this"... imagine in one class, you have a pointer to an object. if you make a simple copy, you would duplicate actually the address, ,not the object pointed. a copy constructor allow you to make a deep copy... virtual destructors is another topic, with no relation with the first one. in a general mean, you tell a destructor to be virtual if you think that you class can be derived.


        TOXCCT >>> GEII power

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

        1 Reply Last reply
        0
        • S Subramaniam s V

          can anyone help me out in clearly understanding the concept of COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. I have gone through lots of books but still i am not much clear as why we go for COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. Kindly help me out.

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          Subramaniam s.V. wrote:

          COPY CONSTRUCTORS

          A copy constructor is used to copy the contents of one object to another. A copy constructor unlike the assignment operator is also responsible for creating the object alongwith the initialization. Ex: class sample { public: sample() { } sample(sample &s) { cout<<"In Copy Constructor:"<

          Subramaniam s.V. wrote:

          VIRTUAL DESTRUCTORS. We need virtual destructors to perform memory cleanup from derived class to the base class.

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          1 Reply Last reply
          0
          • S Subramaniam s V

            can anyone help me out in clearly understanding the concept of COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. I have gone through lots of books but still i am not much clear as why we go for COPY CONSTRUCTORS and VIRTUAL DESTRUCTORS. Kindly help me out.

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

            See here[^] and here[^] maybe it is some helpful to you

            _**


            **_

            WhiteSky


            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