Does the implicitly defined copy constructor in C++ call copy constructor for members too right?

701 views Asked by At

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)

2

There are 2 answers

0
Kleist On BEST ANSWER

Yes, that is exactly what it does.

0
JaredPar On

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.