Topic: Distinguishing object types


Author: "Yosi" <natask@hotmail.com>
Date: 1999/06/30
Raw View
Hi,

I have this problem, and I don't seem to find it a
proper object oriented solution.
Consider this:

There is base class called Base. Base contains two protected data members
for example int a and int b. Two classes, Derive1 and Derive2 public inherit
from class Base. Each derived class has an operator== which looks like this:
Derive1 has this implementation of operator==
bool operator==(const Derive1& anObject)
{ return ((a==anObject.a)&&(b==anObject.b)); }
and Derive2 has this implementation of operator==
bool operator==(const Derive2& anObject)
{ return ((a==anObject.a) && (b==anObject.b)); }

Now, suppose I have 2 objects derive1 of type Derive1 and derive2 of type
Derive2. derive1 data members contain the same values as those of derive2.
I want the comparasion between the different types to give me a 'false'
(not an exception or a run-time error), but currently, it will return 'true'
how can I make this happen, using an object oriented solution (and not by
adding
special data members to Derive1 and Derive2 to 'force' it)?

Thanks in advance.
Yosi
I will be more than grateful if you can post a copy of your reply to my
email address:
natask@hotmail.com




      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]