Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:08:13+00:00 2026-06-03T20:08:13+00:00

Is it OK to use multiple inheritance if one parent class is an interface

  • 0

enter image description here

Is it OK to use multiple inheritance if one parent class is an interface (only contains pure virtual functions with virtual destructor)?

I want to expose only interface part (yellow class in the picture) to increase compile speed. Green part is implementation part. But CPet should inherit from CAnimal(is-a relation) and IPet(implement), there are “Diamond of Death” 🙁

Interface classes (in yellow) only have pure virtual functions and virtual destruction, so when I create CDog, CCat through factory class, there are no problem like ambiguity. CDog has two vtables (from IDog and CPet) but in the virtual function tables, the points indicate same function (CDog member functions).

There’s no compile error, no running error… but I’m worry about this hierarchy.
Is it OK or are there any problems?

PS : I don’t want to use ‘virtual inheritance’ because if I use that, I can’t look into class member variable through watch view.(I guess it is because virtual inheritance link to parent class like linked-list.)

Environment : Visual Studio C++ 2008 or over.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:08:15+00:00Added an answer on June 3, 2026 at 8:08 pm

    Given the description above, you should not be able instantiate an instance of CPet because the pure virtual function IAnimal::isAlive() is undefined in the IPet vtable.

    struct IAnimal {
        virtual ~IAnimal() {}
        virtual void isAlive() = 0;
    };
    
    struct IPet : public IAnimal {
    };
    
    struct CAnimal : public IAnimal {
        virtual void isAlive() {
        }
    };
    
    struct CPet : public CAnimal, public IPet {
    };
    
    int main(void) {
        CPet cp;
    }
    

    Produces the following when compiled with Visual C++ 2008 & 2010:

    animal.cpp(18) : error C2259: 'CPet' : cannot instantiate abstract class
        due to following members:
        'void IAnimal::isAlive(void)' : is abstract
        mytest.cpp(5) : see declaration of 'IAnimal::isAlive'
    

    GCC produces a similiar warning:

    animal.cpp: In function 'int main()':
    animal.cpp:18:7: error: cannot declare variable 'cp' to be of abstract type 'CPet'
    animal.cpp:14:8: note:   because the following virtual functions are pure within 'CPet':
    animal.cpp:3:15: note:  virtual void IAnimal::isAlive()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the other option we can use for multiple inheritance other than implementing interface
I ask myself how use multiple images in one. For example youtube -> http://s.ytimg.com/yt/img/master-vfl102488.png
Is it possible to use multiple header types in one document? For example: header(Content-type:
I want to use multiple private keys to connect to different servers or different
When I want to use multiple windows in my code, I normally do it
I want to use multiple calendars and lose the time axis in the agenda
Can anyone think of any situation to use multiple inheritance? Every case I can
I have multiple html elements. They use very similar css styles. Only difference is
Here's an example using multiple interface inheritance in Java and there's an issue. Note
While certain guidelines state that you should use an interface when you want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.