Consider the following class:
class A {
char *p;
int a, b, c, d;
public:
A(const &A);
};
Note that I have to define a copy constructor
As a rule of thumb: If you have to manually manage resources, wrap each into its own object.
Put that char*
into its own object with a proper copy constructor and let the compiler do the copy constructor for A
. Note that this also deals with assignment and destruction, which you haven't mentioned in your question, but need to be dealt with nevertheless.
The standard library has several types to pick from for that, among them std::string
and std::vector
.