virtual inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noah Roberts

    #1

    virtual inheritance

    Is there anything that says that if you virtually inherit from one
    class you have to virtually inherit from anything you inherit from?

  • Ron Natalie

    #2
    Re: virtual inheritance

    Noah Roberts wrote:
    Is there anything that says that if you virtually inherit from one
    class you have to virtually inherit from anything you inherit from?
    >
    No, if not if I understand your question. You can (and typically do)
    have a mix of virtual and non-virtual inheritance.

    Comment

    • Salt_Peter

      #3
      Re: virtual inheritance

      Noah Roberts wrote:
      Is there anything that says that if you virtually inherit from one
      class you have to virtually inherit from anything you inherit from?
      What? Can you ask your question with an example?
      Your question can be answered ad infinitum and public inheritance is
      not the same as virtual public inheritance, either.

      I see a misconception here. Inheritance does not mean append or attach.
      It means transpose or redesign from scratch. How the redesign takes
      place depends on what member functions are virtual and which ones are
      virtually overridden or even overloaded.
      Also, a ctor and dtor can never be inherited, but a d~tor's vituality
      is inherited.

      Note that composition is far more common than public inheritance -
      which is a strict relationship. If you are trying to circumvent
      inheritance of virtual member functions, chances are that the base
      class should be a member. Hence the term: composition.

      Peter

      Comment

      • werasm

        #4
        Re: virtual inheritance


        Noah Roberts wrote:
        Is there anything that says that if you virtually inherit from one
        class you have to virtually inherit from anything you inherit from?
        What are you actually asking - whether virtual iheritance is carried
        over??? e.g.

        struct Base{};
        struct Derived1 : virtual Base{};
        struct Derived2 : Derived{};

        Derived 2 automatically inherits virtually from Base, as this is
        implied because Derived1 does. Derived2 though, does not automatically
        inherit virtually from Derived1.

        see C++ std 98 par. 10.1/4

        Regards,

        Werner

        Comment

        • Martin Steen

          #5
          Re: virtual inheritance

          Noah Roberts wrote:
          Is there anything that says that if you virtually inherit from one
          class you have to virtually inherit from anything you inherit from?
          >
          No. Only methods with the "virtual"-keyword are virtual inherited. All
          other methods are normal inherited.

          -Martin

          Comment

          • Noah Roberts

            #6
            Re: virtual inheritance


            Ron Natalie wrote:
            Noah Roberts wrote:
            Is there anything that says that if you virtually inherit from one
            class you have to virtually inherit from anything you inherit from?
            No, if not if I understand your question. You can (and typically do)
            have a mix of virtual and non-virtual inheritance.
            Yes, you understand my question. I'm getting very strange results I
            hadn't gotten until I tried virtual inheritance on one class. It is
            affecting a different parent. I didn't think virtual inheritance
            required that but it was worth asking because I have no idea what is
            going on.

            Thread on that is titled "Anyone seen anything like this" or something
            like that. I'll be trying to reproduce it in a simple program today if
            I can.

            Comment

            Working...