Comparing 2 objects

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

hi all, in c++ i could overload an == opperator and then using a template
class i could compare the 2 classes using the overloaded opperators and you
did not have to tell the template what class you were dealign wtih.

in c# iv got a class that has overloaded opperators. later on i them come to
compare them, but the values being compared are objects.

e.g.

class House
{
// overloaded opperators
}

class Town
{
public void (object data)
{
object currentData;
// compare the objects to see if they are the same.
}

when i compare the objects i want to compare them using the overloaded
opperators iv used but they don't get called.

Any help would be grate

Thx Scott
 
scott said:
hi all, in c++ i could overload an == opperator and then using a template
class i could compare the 2 classes using the overloaded opperators and you
did not have to tell the template what class you were dealign wtih.

in c# iv got a class that has overloaded opperators. later on i them come to
compare them, but the values being compared are objects.

e.g.

class House
{
// overloaded opperators
}

class Town
{
public void (object data)
{
object currentData;
// compare the objects to see if they are the same.
}

when i compare the objects i want to compare them using the overloaded
opperators iv used but they don't get called.

Any help would be grate

Well, you haven't shown any of the overloaded operators, and the code
you *have* shown wouldn't compile.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

I wouldn't generally recommend overloading operators to compare two
different types (assuming it's possible - I haven't tried it, but I
suspect it is).
 
Back
Top