STUPID NEWBIE question...
Okay, the problem here is stupidity... But that is not somthing that can be fixed :/
So anyways, I'm learning classes... Everything is going just fine and then I get to the section on the this pointer. I think I understand what the this pointer does... But some of the other code I don't understand.
Code:
softball& softball::topbat(softball& player)
{
if(player.ave > ave)
return player;
else
return *this
}
I don't understand the line with '&' in it... I thought '&' was used for memory addresses...
Help me out please.
Re: STUPID NEWBIE question...
Quote:
Originally posted by Unregistered
Code:
softball& softball::topbat(softball& player)
{
if(player.ave > ave)
return player;
else
return *this
}
softball & // the return type
this means you are returning a softball by reference which basically IS a pointer but it doesn't look that way syntax-wise.
softball & player // the parameter list
you are passing in a softball but it doesn't make a copy. It's the pointer but again, doesn't look that way syntax-wise.
return *this;
you're dereferencing the this pointer. Again, you're actually passing back "this" object by reference.
by reference is essentically a dereferenced pointer. you can use the dot operator conveniently