I'm looking through the c++ tutorial [http://www.cplusplus.com/doc/tutorial/classes2/ under "The keyword this"] and I'm confused on why a member function parameter has "&".
The code:
#include "stdafx.h"
#include <iostream>
class CDummy {
public:
int isitme( CDummy& param ); // <-- Having trouble understanding this
};
int CDummy::isitme( CDummy& param ) // <-- Having trouble understanding this
{
if( ¶m == this)
return true;
else
return false;
}
int main ()
{
CDummy a;
CDummy *b = &a;
if ( b->isitme(a) )
std::cout<< "yes, &a is b";
return 0;
}
Why does int isitme( CDummy& param)
work and not int isitme( CDummy param )
? Also how come in the function implementation it goes if( ¶m == this )
, shouldn't ¶m
only be used if the function declaration were int isitme( CDummy param )
?