关于运算符的重载问题
class Set
{
public:
friend Set operator +(const Set&);
int array[10];
}
请问我在这里friend Set operator +(const Set&);为什么不用friend就错呢?而且(const Set&);这里面非要用const呢?不用就报错呢?
class Set
{
public:
friend Set operator +(const Set&);
int array[10];
}
请问我在这里friend Set operator +(const Set&);为什么不用friend就错呢?而且(const Set&);这里面非要用const呢?不用就报错呢?
是没人说非要用const,但是我要是不用的话,编译器就说我这个运算符重载函数是暧昧的?
我就不明白这是为什么?
还有friend也是一样的,不加就说是暧昧的。
书上说:加了friend,可以直接访问私有的,但是这里,如果把数组设为私有的话,在main()函数里访问的话就报错啊!
走了
你发上来
会有人帮你的
friend Set operator +(const Set&);