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. When is copy constructor must in a class?

When is copy constructor must in a class?

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
2 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.
  • K Offline
    K Offline
    Karismatic
    wrote on last edited by
    #1

    I know the reason that when we need to do shallow copy.But how copy constructor resolve this problem?I am not able to understand. So please reply me as soon as possible.

    Regards, Pankaj Sachdeva

    M 1 Reply Last reply
    0
    • K Karismatic

      I know the reason that when we need to do shallow copy.But how copy constructor resolve this problem?I am not able to understand. So please reply me as soon as possible.

      Regards, Pankaj Sachdeva

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Please post questions not related to managed C++ on the Visual C++/MFC board[^] It's up to you to decide how objects are copied, either using the assignment operator or a copy constructor. The difference between the two is right in the names - An assignment operator assigns the "value" of one object to another object. A copy constructor does the same but it's a constructor - it constructs the destination object. The compiler can only provide default copy semantics for objects based on the class of the object. For any class which doesn't provide operators, this means a bitwise, binary copy. In the case of pointers, this may not be what you want. You may want a copy of the data pointed to by a pointer (deep copy), not just a copy of the pointer (shallow copy). To do this you need to implement assignment operator(s) and/or a copy constructor for a class. Mark

      Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3

      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