C
Christian Christmann
Hi,
I want to clarify that I use the copy constructor correctly.
firstclass.h:
class FirstClass
{
public:
FirstClass();
FirstClass( const FirstClass & );
[...]
private:
SecondClass *mClass;
[...]
};
firstclass.cpp:
FirstClass::FirstClass()
: mClass(NULL)
{
}
FirstClass::FirstClass( const FirstClass © )
{
mClass = new SecondClass (*copy.mClass);
// I am not the author of the class SecondClass but I assume
// that its copy constructor is working fine
}
[...]
Is the copy constructor for FirstClass correct?
I want to assure that the private member mClass of the new (copied)
FirstClass object is pointing to a copy of the class member copy.mClass
and avoid both FirstClass objects pointing to the same copy of mClass.
Chris
I want to clarify that I use the copy constructor correctly.
firstclass.h:
class FirstClass
{
public:
FirstClass();
FirstClass( const FirstClass & );
[...]
private:
SecondClass *mClass;
[...]
};
firstclass.cpp:
FirstClass::FirstClass()
: mClass(NULL)
{
}
FirstClass::FirstClass( const FirstClass © )
{
mClass = new SecondClass (*copy.mClass);
// I am not the author of the class SecondClass but I assume
// that its copy constructor is working fine
}
[...]
Is the copy constructor for FirstClass correct?
I want to assure that the private member mClass of the new (copied)
FirstClass object is pointing to a copy of the class member copy.mClass
and avoid both FirstClass objects pointing to the same copy of mClass.
Chris