【发布时间】:2013-11-28 04:39:12
【问题描述】:
我有一个模板类,我试图使用运算符
Vertex.h:24:16: error: use of deleted function 'std::basic_ostream<char>::basic_ostream(const std::basic_ostream<char>&)'
其中第 24 行指的是以下代码中输出运算符的返回:
/In declaration of templated class Vertex
friend std::ostream operator<<(std::ostream& ost, const Vertex<T>& v) {
ost << v.getItem();
return ost;
}
//In main function
Vertex<int>* v1 = new Vertex<int>();
v1->setItem(15);
cout << *v1 << endl;
我怎样才能让这个输出工作?
【问题讨论】:
-
因为你是通过引用传递ostream,所以通过引用返回它。