#### Archived

This topic is now archived and is closed to further replies.

# short question - short answer plz :)

This topic is 5735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts


class InvNode
{
public:
inline bool operator ==(const Item &rhs){return (item==rhs);};
private:
const Item &item;
};  
error is something about Item not beeing defined as an operator on the left side of == (error code c2678) whats wrong? (item is defined later on in the class, operator== is overloaded in class Item) [edited by - BB-Pest on December 4, 2002 4:48:04 PM]

##### Share on other sites
Try putting the deffinition of Item before you use it.

##### Share on other sites
this did as i guessed not help.

here''s a more direct transaltion of the error message:

binary operator ''=='': No operator defined accepting a left-sided operator of the following type ''const class Item''

##### Share on other sites
You need to define operator== as a const function. (in the Item-class on this case, but preferably in all classes)

bool operator==(const T& rhs) const { ... }

[edited by - civguy on December 4, 2002 5:09:05 PM]

##### Share on other sites
thx for the hint but this did again not help.

##### Share on other sites
You''re overloading the == operator to take a LHS of type InvNode and a RHS of type Item. You still need to have an operator == that takes a LHS of type Item - this would presumably be declared in the Item class, not the InvNode class.

##### Share on other sites
you posted the wrong part of your code. I think the mistake is in the class "Item", not in "InvNode"

[edited by - 123cs on December 4, 2002 5:30:46 PM]

##### Share on other sites
[edit1]Miserable was right[]
...but if need to do it that way i'll do the thing like this:

    if( inInvNode.getItem() == inItem )//instead ofif (anInvNode == anItem) {...};

IMHO thats the cleaner solution, right?

[edited by - BB-Pest on December 4, 2002 5:31:44 PM]

##### Share on other sites
a cleaner solution would be to have a function:
bool InvNode::hasItem(const Item& item_) const {    return (item == item_);}

[edited by - petewood on December 5, 2002 4:24:13 AM]

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 12
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632151
• Total Posts
3004455

×