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. Copy Constructor

Copy Constructor

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 4 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.
  • P Offline
    P Offline
    Prudhvi Raju
    wrote on last edited by
    #1

    Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.

    A B 2 Replies Last reply
    0
    • P Prudhvi Raju

      Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.

      A Offline
      A Offline
      act_x
      wrote on last edited by
      #2

      Copy Constructor is used to solve the problem of Shallow copy when using dynamic data( as in pointers ). as the default copy constructor does a member wise copy of data members , this operation is undesirable while using pointers as both the pointer members point to the same area in memory . This can have undesired effects . By implementing a copy constructor , one can allocate new memory and make sure that space allocated is different . In the case where memory management isnt required the default COPY cONSTRUCTOR will suffice . Engineering is the effort !

      1 Reply Last reply
      0
      • P Prudhvi Raju

        Can any one clarify this: What is the advantage of overwriting a copy constructor when C++, by default, providing one. Thanks, Prudhvi.

        B Offline
        B Offline
        BlackDice
        wrote on last edited by
        #3

        also, remember to always implement a destructor that frees the new memory so that any class that is copied won't cause memory leaks. [insert witty comment here] bdiamond :zzz:

        A 1 Reply Last reply
        0
        • B BlackDice

          also, remember to always implement a destructor that frees the new memory so that any class that is copied won't cause memory leaks. [insert witty comment here] bdiamond :zzz:

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Thank You.

          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