我正在为一个像这样的类重载一个小于运算符:
#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;
};
Run Code Online (Sandbox Code Playgroud)
然后执行文件:
#include "X.h"
bool operator < (X const& lhs, X const& rhs)
{
return lhs.a< rhs.a;
}
Run Code Online (Sandbox Code Playgroud)
但是,它不允许我访问a实现文件中的数据成员,因为它a被声明为私有数据成员,即使它通过X对象?