#include <iostream>
using namespace std;
const int size = 3;
class vector {
int v[size];
public:
vector();
vector(int *x);
friend vector operator * (int a, vector b);
friend vector operator * (vector b, int a);
friend istream & operator >> (istream &, vector &);
friend ostream & operator << (ostream &, vector &);
};
}在上面的代码中,我不能理解
friend istream & operator >> (istream &, vector &);这里,我所知道的是,流用于数据流的输入流,ostream用于输出,但是在>>的操作符重载之前,istream &意味着什么。
发布于 2018-03-16 02:12:55
这意味着它返回对istream对象的引用。这对于操作符链来说是必要的,因为您习惯于使用cout
std::cout << "foo" << "bar";如果不返回对自身的引用,这个部分:<< "bar"是不可能的。
https://stackoverflow.com/questions/49306454
复制相似问题