Two things:
1)
nobody in this thread overloaded the == operator properly. Const correctness, people.
2) You're misunderstanding static members
For #1, the == operator should look like this:
1 2 3 4
|
bool Team::operator == (const Team& obj) const // note the 2 'const's here
{
//...
}
|
For #2, static members are shared
by all objects. They're basically global variables, just with limited scope. Because 'uniqueID' is static, there is
one uniqueID for
all instances of Team. Each team does not have it's own 'uniqueID'.
If you change a static member var in one class, you change it for all classes. They all share the same variable. That's the whole point of the static keyword.
if(this->uniqueID==obj.uniqueID){
<- this will always be true because you're comparing the the same variable to itself. it's like doing this:
1 2
|
int foo = 5;
if(foo == foo){ // will always be true
|
hmm a simple work around was assigning an int called id, to the static uniqueID in the constructor and then comparing the int id instead of the static uniqueID. |
This isn't really a "workaround", this is what you need to do. If you want each team to have it's own ID, you need a non-static member.