C++ Class Copy (pointer copy) -


it understanding when make copy of class defines pointer variable, pointer copied, data pointer pointing not.

my question is: 1 assume "pointer copy" in case instantiating new pointer (dynamic memory allocation) of same type? eg., new pointer new allocation containing arbitrary memory address , 1 should take care point new pointer appropriate memory address?

i presume there quite simple answer question, , apologize trivial nature, trying understand pointers @ deeper level , came upon researching pointers on internet.

regards,

chad

the pointer copied value - both classes point same original memory, no new allocation takes place. shallow copy - language default.

if need allocate new memory , make copy of data have in copy constructor. deep copy - have yourself

edit: 1 of advantages of c++, free decide how copying works. might copy of object read access memory can avoid cost of copying memory. can implement classes make copy of original data if new object needs write.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -