Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure every data members of a class have been copied in its copy constructor?

Tags:

c++

When a class has many data members, it is hard to figure out whether a data member is copied or not in its copy constructor.

Is there a solution?

like image 922
camino Avatar asked Mar 10 '15 18:03

camino


1 Answers

A simple solution is to make sure every member type is copyable, and that there are e.g. no pointers to self or other pointers or references that require fix-ups. Then the generated copy-constructor is good enough.

like image 193
Cheers and hth. - Alf Avatar answered Sep 30 '22 17:09

Cheers and hth. - Alf