CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Rtti

  1. #1
    Join Date
    Oct 1999
    Mumbai, India

    Post Rtti


    Suppose the relationship of two classes viz. Base and Derived
    are such that:

    PHP Code:
    class Base
    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 Mukherjee
    [Email: sayan2405@gmail.com]

  2. #2
    Join Date
    Jan 2004
    Düsseldorf, Germany

    Re: Rtti

    Originally posted by Sayan Mukherjee
    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:
    Base * pBase = 0;
    if ( ... )
      pBase = new Base();
      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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center