求助copy的问题
struct Node
{
int nomber;
int fromx;
int fromy;
int fromz;
int tox;
int toy;
int toz;
bool operator == (const Node& other)const
{
return nomber == other.nomber;
}
Node& operator = (const Node& other)
{
*this = other;
return *this;
}
friend ostream& operator < < ( ostream& os,Node& node);
//Node* next;
};
vector <Node> vn;
....
copy( vn.begin(),vn.end(),ostream_iterator <Node> ( cout, "\n ") );
会有d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\iterator(257) : error C2679: 二进制“ < <” : 没有找到接受“ <未知> ”类型的右操作数的运算符(或没有可接受的转换)
d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\iterator(256) : 编译类模板成员函数“std::ostream_iterator <_Ty> &std::ostream_iterator <_Ty> ::operator =(const _Ty &)”时
with
[
_Ty=Node
]
c:\Documents and Settings\yuzehua\My Documents\Visual Studio Projects\file2\file2\file2.cpp(87) : 参见对正在编译的类模板实例化“std::ostream_iterator <_Ty> ”的引用
with
[
_Ty=Node
]
的错误。貌似operator=有问题,但我不是定义了吗?
[解决办法]
friend ostream& operator < < ( ostream& os,Node& node);
它的实现呢?
[解决办法]
const只是保证引用的对象在函数内不被修改。