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.

see implementing copy constructor.

see copy constructor pointers objects.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -