pablo pablo - 1 year ago 126
C++ Question

How to use both default and own copy constructor in C++?

I have a long class with a lot of members. I want to write copy constructor for it. But if I write my own copy constructor I lost access to deafult copy constructor.

I just want to repair a few pointers in my own copy constructor. So I want to have shallow copy of the object which can be done by default copy constructor.

Is there a possibility to access default copy constructor when there is my own copy constructor already?

Answer Source

Wrap the things you don't want to change in a struct, and derive (privately) from it. In your copy constructor, simply invoke the copy constructor of your base class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download