C++ copy constructor by pointer -
hello want create new class variable pointer , initialize copy constructor. though know how copy constructor works refernce, cannot figure out how it. can me? example have definition:
class a{ public: int a; private: };
and in code segment following:
a *object= new a; a->a=10; *newobject= new a(*object);
but segmentation fault. can me? tried:
*newobject= new a(&(*object));
but doesn't work either.
with kind of simple example, following uses default bit wise copy constructor works fine.
the simple class looks like
class bclass { public: int ivalue; };
and code use copy constructor looks like:
bclass *pobject = new bclass; pobject->ivalue = 10; bclass *pobject2 = new bclass (*pobject);
using microsoft visual studio 2005, above works fine.
Comments
Post a Comment