C++ “类没有成员”;操作员<<&引用;
我已经通读了,看起来像是类似的问题,但没有解决我自己的问题 我的头文件:C++ “类没有成员”;操作员<<&引用;,c++,insertion,ostream,C++,Insertion,Ostream,我已经通读了,看起来像是类似的问题,但没有解决我自己的问题 我的头文件: using namespace std; class Animal { private: friend ostream & operator<< (ostream & o, Dog & d); int number; public: Animal(int i); int getnumber(); }; ostream & operator&
using namespace std;
class Animal {
private:
friend ostream & operator<< (ostream & o, Dog & d);
int number;
public:
Animal(int i);
int getnumber();
};
ostream & operator<< (ostream & o, Dog & d);
使用名称空间std;
类动物{
私人:
friend ostream&operator它不是Animal
类的成员,也不应该是。因此不要将其定义为一个。通过删除Animal::
前缀将其定义为自由函数
ostream & operator<< (ostream & o, Dog & d){
//...
}
ostream&operator如果不想成为运算符
ostream & operator<< (ostream & o, Dog & d){
//...
}