Archived

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

platypusman

ambiguous operators

Recommended Posts

Hi, I''m building a simple particle engine for a class project using C++. I''ve been trying to make it as modular and extensible as possible. Right now I''m placing all of my systems into an STL list. This list then gets managed by a ParticleManager class. Anyways, I''m having some trouble when removing a system from the manager. Every system has an id with which I intend to track it to change parameters etc... I defined operators on it as follows. bool operator<(const ParticleSystem &o1, const ParticleSystem &o2) { return o1.id < o2.id; } bool operator>(const ParticleSystem &o1, const ParticleSystem &o2) { return o1.id > o2.id; } bool operator==(const ParticleSystem &o1, const ParticleSystem &o2) { return o1.id == o2.id; } bool operator!=(const ParticleSystem &o1, const ParticleSystem &o2) { return o1.id != o2.id; } But when I compile the code I get the following error in Visual C++ 6.0: "error C2593: ''operator =='' is ambiguous". Does anyone have any ideas of what is going on? Thanks

Share this post


Link to post
Share on other sites
If something is ambiguous the compiler is unable to determine which function it should use, because the calling convention of one or more functions is equal.

The '=='-operator is already defined in your case. That is why the compiler can't tell if it should use your version of '==' or the one that's already provided.

//edit: Here's an example that might help clarify things:


class Point
{
...

public:
// '=='-operator provided by class Point
bool operator == (const Point& point)const;
}



// '=='-operator provided externaly, with 'const Point&' as parameter.
bool operator==(const Point& p1,const Point& p2)const
{
...
}

...
Point p1;
Point p2;

if (p1 == p2) // Ambiguous! Use the '==' provided by Point, or the one provided externaly?
...



So, my best guess is that ParticleSystem provides an operator-'==' that expects a const ParticlySystem& as parameter.

[edited by - Wildfire on November 16, 2003 1:47:53 PM]

Share this post


Link to post
Share on other sites