Why "this" pointer can access private member?

16/11/2003 - 17:14 por Anonimo | Informe spam
//nest3.h file.
class C1
{
public:
C1(int value)
{
_value = value;
};
bool operator==(C1 &) const;

private:
int _value;
};







//"nest3.cpp" file
#include "nest3.h"
#include <iostream>
using namespace std;
inline bool C1::operator ==(C1 &rhs) const
{
return this->_value==rhs._value; //Why "this" pointer can access rhs's
private data member directly here?
}

int main()
{
C1 c1_1(10);
C1 c1_2(10);
cout<<c1_1.operator==(c1_2)<<endl;
return 0;


}
 

Leer las respuestas

#1 Edward
16/11/2003 - 15:32 | Informe spam
Because the bool operator==(C1 &) const
is member function of C1

дÈëÓʼþ news:eGfMsA$
//nest3.h file.
class C1
{
public:
C1(int value)
{
_value = value;
};
bool operator==(C1 &) const;

private:
int _value;
};







//"nest3.cpp" file
#include "nest3.h"
#include <iostream>
using namespace std;
inline bool C1::operator ==(C1 &rhs) const
{
return this->_value==rhs._value; //Why "this" pointer can access


rhs's
private data member directly here?
}

int main()
{
C1 c1_1(10);
C1 c1_2(10);
cout<<c1_1.operator==(c1_2)<<endl;
return 0;


}



Preguntas similares