Page 1 of 1

Why does Player.h create two instances of itself in its public definition?

Posted: Sat Jun 03, 2017 8:55 am
by gabespound
In player.h, it opens the class CPlayer and starts with these lines
public:
CPlayer();
virtual ~CPlayer();

My first question is what exactly is virtual and what is the ~ mean next to the CPlayer (For some reason ~ looks like a dash on this forum, it is a tilde(squiggly line))? Secondly, What is the purpose of creating a instance of itself inside the header file? Later on in the Player.Cpp file it does this

CPlayer::CPlayer()
: m_pInput(nullptr)
, m_pMovement(nullptr)
, m_pView(nullptr)
{
}

CPlayer::~CPlayer()
{
gEnv->pGameFramework->GetIActorSystem()->RemoveActor(GetEntityId());
}

What is going on in those lines? To me it looks like it is defining the CPlayer() from player.h to have null values for input movement and view. Then it takes the ~CPlayer from player.h and removes the actor? Please explain. Thanks

Re: Why does Player.h create two instances of itself in its public definition?

Posted: Sat Jun 03, 2017 9:39 am
by mknmknmknjk
https://stackoverflow.com/questions/461 ... estructors


CPlayer is Game Object Extensions, which must attach to gameobject. when all extention attach success, call Init(GameObject ) on each extensions, the parameter gameobject represent gameobject which is essence an entity compliant to IGameObject Extension. it is safer to obtain other attach extension in init function and after init.

Re: Why does Player.h create two instances of itself in its public definition?

Posted: Mon Jun 05, 2017 1:31 pm
by sunnlok
It seems to me that you have no real grasp on how cpp works, since those are the absolute basics for it.
CPlayer() doesnt create a new instance, its the definition for the constructor, which will then be implemented in the cpp file.
Same for ~CPlayer() which is the destructor.