Windows XD Windows XD - 4 years ago 123
C++ Question

C++ Copy pointer class

I have a problem. I'm kinda new to C++, so please keep that in mind ^^ So I have function called

::Save( Player* pPlayer )
in which I'm inserting into map
copy of the player. But firstly I need to create copy of that player, but how? Should I make
Player* pNewPlayer = new Player();
and then...
pNewPlayer = pPlayer
*pNewPlayer = *pPlayer
? It has to be on new address so it won't get modified later. Thanks for help.

Answer Source

You need to call a copy c'tor.

Player* pNewPlayer = new Player(*pPlayer);

And be sure not to dereference a null valued pointer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download