I have a class that has multiple member variables, among which only one is a pointer that requires deep copying. Because of this single pointer I need to define my custom CCTOR and have to copy every single variables manually. Is this a way to avoid this? Of course I could have just used a std::string but that is not the point of this question.
class Foo {
public:
Foo(const Foo& other) {
// deep copying c_str
cout << "Calling copy constructor" << endl;
c_str = new char[strlen(other.c_str) + 1];
strcpy(c_str, other.c_str);
// laboriously copying... is there a way to avoid this?
a = other.a, b = other.b, c= other.c;
}
private:
int a, b, c;
char* c_str;
};