question about using "this"
I have a class called Period and inside of it two functions, one called Sub() and another called IsGreater(): They are called in the form
1 2
|
z = a.Sub(b) //subtract b from a return result
if (c.IsGreater(d)) //if c is greater than d return true
|
My question is, I'm trying to call IsGreater inside of Sub but I cannot figure out how to use "this" work.
1 2 3 4 5 6 7 8 9 10 11
|
I want:
Period Sub(Period b)
{
Period temp;
if (this.IsGreater(b)) //where this should refer to Period a
{
//DO STUFF
}
return temp;
}
|
'this' is a pointer, so you would use the -> operator instead of the . operator.
1 2 3 4
|
if(this->IsGreater(b))
{
// ...
}
|
But of course.. the 'this' is implied when you call it from another member function. So you can just leave it out entirely:
THANKS A MILLION!
Topic archived. No new replies allowed.