Hi,
Consider the following class:
class A {
char *p;
int a, b, c, d;
public:
A(const &A);
};
In the above I have to define a copy constructor in order to do a deep copy of "p". This has two issues:
most of the fields should simply copied. Copying them one by one is ugly and error prone.
the more important problem is that whenever a new attribute is added to the class copy constructor should also be updated and this creates a maintenance nightmare.
I personally like to do something in theory like:
A(const A &a) : A(a)
{
// do deep copy of p
.
.
.
}
So the default copy constrictor is called first and then the deep copy is performed but unfortunately this doesn't seem to work. Is there any better way to do this (I can't use shared/smart pointers.)
But unfortunately this doesn't work. Do you have a better solution?
Thanks in advance!