Topic: type_info
Author: "B. Dalton" <bdalton@xagony.ilo.dec.com>
Date: 1996/01/17 Raw View
The April draft says(see
http://www.cygnus.com/misc/wp/draft/lib-support.html#lib.support
.rtti) about type_info::operator==
bool operator==(const type_info& rhs) const;
Effects:
Compares the current object with rhs.
Returns:
true if the two values describe the same type.
What does "same" mean here? To be specific, say we had
...
class beatha{public:virtual ~beatha(){};}
class duine:public beatha{};
class gael: public duine {};
beatha *pd=new gael;
if(typeid(pd)==typeid(duine)
{ cout<<"duine";
}
...
does "duine" get printed here or not?
--
B. Dalton DEC - Gaillimh
mailto:bdalton@xagony.ilo.dec.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/01/18 Raw View
>>>>> "BD" == "B Dalton" <bdalton@xagony.ilo.dec.com> writes:
BD> class beatha{public:virtual ~beatha(){};}
BD> class duine:public beatha{};
BD> class gael: public duine {};
BD> beatha *pd=new gael;
BD> if(typeid(pd)==typeid(duine)
BD> { cout<<"duine";
BD> }
BD> ...
BD> does "duine" get printed here or not?
No, it doesn't since typeid(pd) = typeid(beatha*).
You probably meant `if(typeid(*pd)==typeid(duine)) ...',
but even then the answer is `no': typeid(*pd)==typeid(gael).
Daveed
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]