【发布时间】:2013-09-05 21:49:10
【问题描述】:
我正在为这样的类重载小于运算符:
#include<string>
using namespace std;
class X{
public:
X(long a, string b, int c);
friend bool operator< (X& a, X& b);
private:
long a;
string b;
int c;
};
然后是实现文件:
#include "X.h"
bool operator < (X const& lhs, X const& rhs)
{
return lhs.a< rhs.a;
}
但是它不允许我访问实现文件中的a 数据成员,因为a 被声明为私有数据成员,即使它是通过X 对象?
【问题讨论】: