![]() |
Question Regarding Constructor Implementation
I have a class that has as a private data member a pointer of the same type.
E.g. The class is "ClassA" and has as a member "ClassA* _classA". I am writing the copy constructor of ClassA, and would like to do a "deep copy" of data member _classA, e.g.: ClassA::ClassA(const ClassA& orig) : _classA(NULL) { if (orig._classA != NULL) { _classA = new ClassA(*(orig._classA)); } } Is that allowed? Thanks in advance, chasse |
Re: Question Regarding Constructor Implementation
_classA = new ClassA(*(orig._classA));
would mean a cyclic reference |
Re: Question Regarding Constructor Implementation
Yes it should be OK. What happens if you try it?
|
Re: Question Regarding Constructor Implementation
Quote:
If You wanna on stack , your code may be tackle like this Code:
class ClassACode:
class ClassADo as your requirement. |
| All times are GMT +5.5. The time now is 05:59. |