Comparison operator "no match" error
I have searched the site for something similar, however the other posts on "no match for operator" errors do not help in my situation.
I have a str开发者_如何学运维uct node in the beginning, and then the following piece of code:
Function end() returns a type node. Therefore the statement op != end(OPEN) should resolve just fine, however I am getting the error: no match for 'operator!=' in '*op != end(OPEN)'
I am using G++ compiler. Does anyone know what I am doing wrong? I have been trying just about anything for hours... Thanks
typedef struct node {
bool h1;
bool w1;
bool h2;
bool w2;
bool h3;
bool w3;
bool b;
int operation;
int iterator;
node *parent;};
node end ( list l ) {
node *n;
return *n;}
bool exists ( node *s, list OPEN, list CLOSED ){
node op;
node cl;
op = begin(OPEN);
cl = begin(CLOSED);
int x;
for(; op != end(OPEN); x++)
{
if( (*(*op)) == (*s) )
{
break;
}
}
You need to define a comparison operator for your node
type:
bool operator!=( const node& lhs, const node& rhs );
Edit:
Just define an equality comparison, then define inequality in terms of that:
bool operator==( const node& lhs, const node& rhs ) {
return ...; // whatever
}
bool operator!=( const node& lhs, const node& rhs ) {
return !( lhs == rhs );
}
Also, these don't have to be member functions, unless you access private members.
op != end(OPEN)
You are trying to compare two node
structures but there is no comparison operator defined for them.
I'm not sure what your code even does. Are you trying to compare the structure values or just the pointers? And what is the end
function supposed to do? Right now, it causes undefined behaviour because you are dereferencing an uninitialized pointer.
精彩评论