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 4003822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:11:55+00:00 2026-05-20T08:11:55+00:00

I have a common interface that many classes in my project inherit (FWIW it’s

  • 0

I have a common interface that many classes in my project inherit (FWIW it’s a ref-counting interface). This interface is inherited by both classes and other interfaces. Instead of re-implementing the interface in every class, I’d like to just have a corresponding implementation class that all the other classes inherit. The problem is the way I have it laid out leads to a diamond-of-death.

struct IBar {
    virtual VOID Bar() = 0;
};

struct CBar : IBar { // implementation class for IBar
    VOID Bar() { }
};

struct IFooBar : IBar {
    virtual VOID Foo() = 0;
};

struct CFooBar : IFooBar, CBar { // implementation of IFooBar interface
    VOID Foo() { }
    // Bar() should be implemented by the inheritance of CBar
};

If I try to compile, I get the following error:

error C2259: 'CFooBar' : cannot instantiate abstract class
1>          due to following members:
1>          'void IBar::Bar(void)' : is abstract

I realize I can fix this by implementing CFooBar::Bar() { return CBar::Bar(); } or having IFooBar inherit from CBar but I suspect there’s a less hacky way of solving this. Any suggestions would be greatly appreciated.

  • 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-05-20T08:11:56+00:00Added an answer on May 20, 2026 at 8:11 am

    You could try always virtually inheriting from IBar. That way, you cut out the middleman, so to speak, and always directly inherit from it regardless if you also inherit from one of its decendents.

    Eg:

    class IBar {
        public:
        virtual void Bar() = 0;
    };
    
    class CBar : public virtual IBar { // implementation class for IBar
        public:
        void Bar() { printf("bar\n");}
    };
    
    class IFooBar : public virtual IBar {
        public:
        virtual void Foo() = 0;
    };
    
    class CFooBar : public IFooBar, public CBar { // implementation of IFooBar interface
        public:
        void Foo() { }
        // Bar() should be implemented by the inheritance of CBar
    };
    
    int main(int argc, char *argv[])
    {
        CFooBar cfb;
    
        cfb.Bar( );
    
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

    I’d always recommend using class over struct if you are writing any member functions – such a thing is, after all, by definition a class. Also, it’s worth explicitly setting access modifiers as in my example (the above code doesn’t actually compile without adding them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two related classes which share a common interface and are both stored
I have a small hierarchy of classes that all implement a common interface. Each
I have a project where there are multiple applications that have some common configuration
i have several common elements (components), that will generate some html. it seems my
I would love to be able to have a common set of Classes in
Is it right by saying it's common to have some interface members not implemented
I have a situation where I have an interface that defines how a certain
We have many classes published in a remoting channel as singlecalls. The application resides
I have a set of classes ( MyClass1, MyClass2, MyClass3 ) that implement an
I have two Java class hierarchies that share a common ancestor and implement a

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.