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

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    4

    Question Virtual inheritance and constructors

    So I have three classes:
    Code:
    class Base {
      int i;
    public:
      Base(int value) : i(value) {}
    };
    
    class Derived : virtual public Base {
    public:
      Derived(int value) : Base(value) {}
    };
    
    class VeryDerived : public Derived {
      VeryDerived(int value) : Derived(value) {}
    };
    I think I misunderstand how virtual inheritance and c++ constructors interact. This all seems to be reasonable, but my compiler tells me that VeryDerived cannot compile because there's no default Base constructor. None of the articles I've found online seem to mention this issue. Can anybody clarify my misunderstanding?

    EDIT: by the way, I understand that in this limited example there's no need for virtual inheritance, but I am boiling down an issue that I'm having with something that I intend to be multiply-inherited. In my real program, I want to both make a non-multiply-inherited subclass of Derived and a multiply-inherited subclass of Derived.
    Last edited by Rossman231; February 22nd, 2009 at 01:09 PM. Reason: Clarification.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured