1

Just want to double check that the default (implicitly defined by compiler) copy constructor for C++ classes performs the copy constructor on each member variable as well using the old value to get the copied value for each member and for atomic objects just uses a bit copy (e.g. ints and floats)

WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • possible duplicate of [C++ copy constructor a class that contains other objects](http://stackoverflow.com/questions/1810163/c-copy-constructor-a-class-that-contains-other-objects) – Martin York Feb 07 '11 at 23:35
  • 2
    "Default constructor" is a technical construct, which makes this question confusing, since you are in fact referring to the *implicitly defined copy constructor* and not to a *default constructor* (either user or implicitly defined. Consider rewording the question to something like: "Will implicitly defined copy constructor call the member copy constructors?" or the like. – David Rodríguez - dribeas Feb 08 '11 at 00:16

2 Answers2

4

Yes, that is exactly what it does.

Kleist
  • 7,785
  • 1
  • 26
  • 30
3

Yes. The default copy constructor in C++ will be member-wise copy initialization for every member in the type.

As to how exactly the copy is done for primitive types such as int and float I cannot say for certain. My guess is it's implementation specific but most compilers just do a bit by bit copy.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454