What is a nonstatic member function?

SirYakalot picture SirYakalot · Sep 29, 2011 · Viewed 26.4k times · Source

I am being told that I can't use the 'this' keyword in a class function. I'm coming from c# and i'm used to this working, but the compiler tells me that it can only be used within nonstatic member functions.

D3DXVECTOR3 position;

void Position(D3DXVECTOR3 position)
{
    this.position = position;
}

Answer

Pubby picture Pubby · Sep 29, 2011

this is a pointer containing the address of the object.

D3DXVECTOR3 position;

void YourClassNameHere::Position(D3DXVECTOR3 position)
{
    this->position = position;
}

Should work.

D3DXVECTOR3 position;

void YourClassNameHere::Position(D3DXVECTOR3 position)
{
    (*this).position = position;
}

Should also work.