Mulitple Inheritance

This is a discussion on Mulitple Inheritance within the C++ Programming forums, part of the General Programming Boards category; Hello there! My first post here. I'm attempting to use static_cast to upcast a Base object (which gets downcast using ...

  1. #1
    DMJ
    DMJ is offline
    Registered User
    Join Date
    Aug 2004
    Posts
    1

    Mulitple Inheritance

    Hello there! My first post here.

    I'm attempting to use static_cast to upcast a Base object (which gets downcast using dynamic_cast beforehand for storage in a container). It seems to work great on objects that are not involved in the multiple inheritance I have set up.

    Code:
    The inheritance: 
                              Base
                             /    \
                      Derived   Derived2
                            \     /  
                           Derived3
    Classes Derived and Derived2 are virtual to allow for the creation of Derived 3.

    Any upcasting with static_cast seems to work with a derived class that is not involved in multiple inheritacne, and incidentally not virtual.

    Does anyone have any pointers (ha!) for using static_cast (or any cast that will work) to return my dowcasted base object back to its proper derived class?

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Code:
    Classes Derived and Derived2 are virtual to allow for the creation of Derived 3.
    By that, I'm assuming you mean that Derived3 inherits them virtually, not that Derived and Derived2 simply have virtual functions. Would you be able to show us the error that you get (or does the code just fail)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Inheritance and program structure planning please help a newbie
    By ninjacookies in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2005, 12:18 PM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 08:04 AM
  4. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21