"Sowen" <sowen@anggogo.com> wrote in message
news:d12abd$5mv$1@canopus.cc.umanitoba.ca...[color=blue]
> Hi, all[/color]
Hi.
To begin, the answer to your question does
not depend on anything related to the usual
"stack" in C++ discussions.
[color=blue]
> for example
>
> in my parent class, I define "virtual bool operator==(const parent &other);"
>
> In my children class, I need to override this method, how can I convert "parent &other" to children so that I can access
>
> ((children)other).getChildName()[/color]
I will assume that 'children' is derived from 'parent',
and that there may be siblings to 'children', (such
as 'bastard_children', 'foster_children', etc.).
Unless you have some way of knowing for sure that
instances of different classes will not be compared
using your operator==(), use code like this:
children * validated_other = dynamic_cast<children *>(& other);
if (validate_other == 0)
return false;
// Whatever is needed to determine and return equality.
If you do know for sure that only instances of the
same type will be compared, you can change the
dynamic_cast to a static_cast and discard the test.
[color=blue]
> I know it's not correct in C++, can I do that ?[/color]
Yes, but not as you first wrote.
--
--Larry Brasfield
email:
donotspam_larry_brasfield@hotmail.com
Above views may belong only to me.