私は C++ の初心者で、私の周りには多くの質問があります。!=
の演算子を定義int_node
しましたが、このコードをコンパイルするとエラーが表示されます:
バイナリ式 ('int_node' および const 'int_node') に対する無効なオペランド
私が使用している IDE は xcode 4.6 です。
以下は私のすべてのコードです
typedef struct int_node{
int val;
struct int_node *next;
} int_t;
template <typename Node>
struct node_wrap{
Node *ptr;
node_wrap(Node *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;}
} ;
template <typename Iterator, typename T>
Iterator find(Iterator first, Iterator last, const T& value)
{
while (first != last && *first != value) // invalid operands to binary experssion ('int_node' and const 'int_node')
{
++first;
return first;
}
}
int main(int argc, const char * argv[])
{
struct int_node *list_head = nullptr;
struct int_node *list_foot = nullptr;
struct int_node valf;
valf.val = 0;
valf.next = nullptr;
find(node_wrap<int_node>(list_head), node_wrap<int_node>(list_foot), valf);
return (0);
}