Is it possible to "add" to the default copy constructor?
Eg. For this class:
class A
{
public:
int a;
int* b;
};
I want to just write
A::A(const A& rvalue):
a(rvalue.a),
b(new int(*(rvalue.b)))
{}
without the a(rvalue.a)
part.
(Ignore the bad/ugly code and possible memory leaks)
What you ask for is impossible. Once you declare your own copy constructor the compiler will not generate a copy constructor for you. That means you won't be able to simply add or augment the default copy constructor because it won't exist. It's all or nothing, so to speak.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With