首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于this->a==a.a&&this->b==a.b,该怎么解决

2013-03-22 
关于this-aa.a&&this-ba.b#include iostreamusing namespace stdclass fun{private:int aint b

关于this->a==a.a&&this->b==a.b
#include <iostream>

using namespace std;
class fun{
private:
int a;
int b;
public:
 fun(int x=0,int y=0){a=x;b=y;}
 bool operator==(fun &a){if(this->a==a.a&&this->b==a.b)//为什么a.a可以访问a的私有成员
 return true;
 else return false;
  }
};
int main()
{
    fun a(1,1),b(1,1),c(2,2);
    cout<<(a==b)<<endl;
    cout<<(b==c)<<endl;
    cout << "Hello world!" << endl;
    return 0;
}

[解决办法]
因为(静态或者非静态)成员函数体还属于类作用域内,private的成员可以在本类作用域或者其友元中可以访问。 

热点排行