我有以下错误代码:
(Visual Studio 错误:)错误 5 错误 C2678: 二进制 '!=' : 未找到采用“节点”类型的左操作数的运算符(或没有可接受的转换)
template <class C, class T>
C find2 ( C first , C last, T c )
{
//
while ( first != last && *first != c )
{
++first;
}
return first;
}
struct Node
{
Node(int a ,Node* b):val(a),next(b){};
int val;
Node* next;
};
template <class T>
struct node_wrap
{
T* ptr;
node_wrap ( T* p = 0 ) : ptr ( p ) {}
Node& operator*() const {return *ptr;}
Node* operator->() const {return ptr;}
node_wrap& operator++ () {ptr = ptr->next; return * this;}
node_wrap operator++ ( int ) {node_wrap tmp = *this; ++*this; return tmp;}
bool operator== ( const node_wrap& i ) const {return ptr == i.ptr;}
bool operator!= ( const node_wrap& i ) const {return ptr != i.ptr;}
};
bool operator== ( const Node& node, int n )
{
return node.val == n;
}
int main()
{
Node* node1=new Node(3,NULL);
Node* node2=new Node(4,NULL);
node1->next = node2;
find2 ( node_wrap<Node>(node1), node_wrap<Node>(), 3) ) ;
delete node1;
delete node2;
return 0;
}
这段代码有什么问题?