Creating an easy to maintain copy constructor

后端 未结 9 2616
夕颜
夕颜 2021-02-19 13:55

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

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 14:09

    The question is, do you really need a pointer with deep-copy semantics in your class? In my experience, the answer almost always is no. Maybe you could explain your scenario, so we may show you alternative solutions.

    That said, this article describes an implementation of a smart-pointer with deep-copy semantics.

提交回复
热议问题