Is there any way to reference the source object of a function?
Something like that.Code:class MyClass
{
void SetIt(SomeType Object)
{
Object.SomeVariable = the instance of MyClass that this function was called for;
}
}
Printable View
Is there any way to reference the source object of a function?
Something like that.Code:class MyClass
{
void SetIt(SomeType Object)
{
Object.SomeVariable = the instance of MyClass that this function was called for;
}
}
Is this what you mean?Quote:
Originally Posted by Loduwijk
Member functions are automatically granted access to member variables of their own object. SomeOtherVariable could be rewritten as this->SomeOtherVariable. "this" is a special keyword, meaning "A Pointer To the Current Object".Code:class MyClass
{
int SomeOtherVariable
void SetIt(SomeType& Object)
{
Object.SomeVariable = SomeOtherVariable
}
}
Note the use of the & - Otherwise you will be dealing with a copy of the SomeType object (Which I assume you don't want).
The "this" keyword is what I was after, yes. Thank you.