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;
}
Non-static data members are the variables that are declared in a member specification of a class.
A non-static member function can be called only after instantiating the class as an object. This is not the case with static member functions. A static member function can be called, even when a class is not instantiated. A static member function cannot have access to the this pointer of the class.
A non-member function always appears outside of a class. The member function can appear outside of the class body (for instance, in the implementation file). But, when you do this, the member function must be qualified by the name of its class. This is to identify that that function is a member of a particular class.
Member functions do not include operators and functions declared with the friend specifier. These are called friends of a class. You can declare a member function as static ; this is called a static member function. A member function that is not declared as static is called a nonstatic member function.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With