-
April 12th, 2004, 01:50 PM
#1
Rtti
Hi,
Suppose the relationship of two classes viz. Base and Derived
are such that:
PHP Code:
class Base
{
};
class Derived : public Base
{
};
The class Base contains at least one virtual function.
We can do the following:
PHP Code:
Base *pBase = new Base();
Derived *pDerived = new Derived();
pBase = pDerived;
This demonstrates polymorphism in C++.
My question is:
Is this behaviour included under RTTI?
Though this does not need to use dynamic_cast, type_id and
type_info, this also is a form of identifying type at runtime.
The limitation is: it is 'up the inheritance chain' only instead of
anywhere in the class hierarchy.
Thanks is advance.
With best regards,
Sayan Mukherjee
[Email: sayan2405@vsnl.net]
Thank you.
Sayan
====================
Sayan Mukherjee
[Email: sayan2405@gmail.com]
-
April 13th, 2004, 04:46 AM
#2
Re: Rtti
Originally posted by Sayan Mukherjee
Code:
Base *pBase = new Base();
Derived *pDerived = new Derived();
pBase = pDerived;
Is this behaviour included under RTTI?
There is no RTTI involved here, just static type checking.
The fact that an object of Derived is-an object of Base is defined statically, it can be checked at compile time, not at run time. RTTI is only needed if you have to evaluate dynamic type information. Example:
Code:
Base * pBase = 0;
if ( ... )
pBase = new Base();
else
pBase = new Derived();
// We cannot determine at compile time if the following will succeed
Derived *pDerived = dynamic_cast<Derived*>(pBase);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|