Saturday, September 4, 2021

copy constructor in C++

copy constructor in C++

    Geeks stuff

  1. Copy Constructor in C++
  2. What is a copy constructor? A copy constructor is a member function that initializes an object using another object of the same class. A copy constructor has the following general function prototype:

    ClassName (const ClassName &old_obj);

    this link has other 5 links of topics as following links:

  3. Copy constructor vs assignment operator in C++
  4. This is a paragraph.

  5. When is copy constructor called?
  6. This is a paragraph.

  7. When should we write our own copy constructor?
  8. Advanced C++ | Virtual Copy Constructor
  9. This is a paragraph.

  10. advacned| virtual constructor
  11. Why copy constructor argument should be const in C++?
  12. This is a paragraph.

    CPP reference: constructor list

  13. Move constructors
  14. move constructor:A move constructor of class T is a non-template constructor whose first parameter is T&&, const T&&, volatile T&&, or const volatile T&&, and either there are no other parameters, or the rest of the parameters all have default values..

    all these good links are worthy to working on it:

    1. converting constructor
    2. copy assignment
    3. copy constructor
    4. copy elision
    5. default constructor
    6. destructor
    7. explicit
      • initialization
      • aggregate initialization
      • constant initialization
      • copy initialization
      • default initialization
      • direct initialization
      • initializer list
      • list initialization
      • reference initialization
      • value initialization
      • zero initialization
    8. move assignment
    9. new

    Good Basics

  15. Automatics, Copy Constructor, Assignment Operator
  16. basics...

  17. What is the difference between memberwise copy, bitwise copy, shallow copy and deep copy?
  18. Member-wise Copy Is when you visit each member and explicitly copy it, invoking its copy constructor. It is usually tantamount to deep-copy. It is the right and proper way of copying things. The opposite is bit-wise copy, which is a hack, see below.

    Bit-wise Copy Is a specific form of shallow copy. It is when you simply copy the bits of the source class to the target class, using memcpy() or something similar. Constructors are not invoked, so you tend to get a class which appears to be all right but things start breaking in horrible ways as soon as you start using it. This is the opposite of member-wise copy, and is a quick and dirty hack that can sometimes be used when we know that there are no constructors to be invoked and no internal structures to be duplicated. For a discussion of what may go wrong with this, see this Q&A: C++ bitwise vs memberwise copying?

    Shallow Copy Refers to copying just the immediate members of an object, without duplicating whatever structures are pointed by them. It is what you get when you do a bit-wise copy. (Note that there is no such thing as "shadow copy". I mean, there is such a thing, in file systems, but that's probably not what you had in mind.)

    Deep Copy Refers to not only copying the immediate members of an object, but also duplicating whatever structures are pointed by them. It is what you normally get when you do member-wise copy.

    To summarize:There are two categories:

    1. Shallow Copy
    2. Deep Copy

    Then, there are two widely used techniques:

    1. Bit-wise Copy (a form of Shallow Copy)
    2. Member-wise Copy (a form of Deep Copy).

  19. Can I make a bitwise copy of a C++ object?
  20. Can C++ objects be copied using bitwise copy? I mean using memcopy_s? Is there a scenario in which that can go wrong?

  21. C++ bitwise vs memberwise copying? [closed]
  22. This is a paragraph.

  23. The disadvantages of bitwise copying. Example. The need to use the copy constructor and copy operator for classes containing dynamic memory allocation
  24. This is a paragraph.

  25. Memory Leak: Bit-Wise and Member-Wise Copy in C++
  26. This is a paragraph.

  27. Shallow Copy and Deep Copy in C++
  28. In general, creating a copy of an object means to create an exact replica of the object having the same literal value, data type, and resources.

    • Copy Constructor
    • Default assignment operator.

No comments:

Post a Comment