• Advertisement

Archived

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

short question - short answer plz :)

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 of


if (anInvNode == anItem) {...};


IMHO thats the cleaner solution, right?

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

  • Advertisement