Thread View: comp.std.c++
2 messages
2 total messages
Started by John Max Skaller
Mon, 29 Jan 1996 00:05
typeinfo
Author: John Max Skaller
Date: Mon, 29 Jan 1996 00:05
Date: Mon, 29 Jan 1996 00:05
24 lines
1425 bytes
1425 bytes
> 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?
No. pd denotes an object of exact type "gael".
This is not the same type as "duine".
[Note "beatha" is polymorphic]
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 web: http://www.maxtal.com.au/~skaller/
AUSTRALIA email: skaller@maxtal.com.au
---
[ 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. ]
Re: typeinfo
Author: steven2
Date: Fri, 02 Feb 1996 15:49
Date: Fri, 02 Feb 1996 15:49
29 lines
1327 bytes
1327 bytes
John Max Skaller <maxtal@suphys.physics.su.oz.au> wrote:
>> 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?
>No. pd denotes an object of exact type "gael".
I believe typeid (pd) is typeid (betha*). What I think you wanted is
if (typeid (*pd) == typeid (duine))
and so (typeid (*pd) == typeid (gael)) will evaluate to true.
Steve
[ 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://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads