help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtaining the name of the C++ class from the pointer


From: Andreas Schallenberg
Subject: Re: Obtaining the name of the C++ class from the pointer
Date: Tue, 02 May 2006 10:03:07 +0200
User-agent: KNode/0.10.2

Paul Pluzhnikov wrote:

> Andreas Schallenberg <no_reply@yahoo.com> writes:
> 
>> X * ptr;
>> cout << "type is " << typeid(*ptr).name() << endl;
> 
> Just a word of caution: if X doesn't have virtual functions,
> typeid(*ptr) will "answer" X even if "ptr" points to a subclass of X.
> ...

Good point!

It is wise to have at least the destuctor virtual
for the candidate classes. This is sufficient to make
the RTTI work, AFAIK.

RU,
Andreas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]