473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple inheritance, dominance and pure base class

Hello,

I have a class tree that looks like

class BaseInterface
{
public:
virtual void f1() = 0;
};

class DerivedInterface : public BaseInterface
{
public:
virtual void f2() = 0;
};

class CommonImplementation
{
public:
void f1() {}
};

class X : public DerivedInterface, public CommonImplementation
{
public:
void f2() {}
};

X* x = new X(); // <--- compiler error: can't instantiate
abstract clas, because f1 is still a pure virtual method

Why can't I instantiate X? And which workarounds are there? Naively I
would expect that the pure BaseInterface::f1() is overriden by
CommonImplementation::f1() and DerivedInterface::f2() is overriden by
X::f2().

Thanks for your help!

-Matthias

Dec 10 '05 #1
2 1821
If I change it to the following tree it works... Why does the first
method fail?

class BaseInterface
{
public:
virtual void f1() = 0;
};
class DerivedInterface
{
public:
virtual void f2() = 0;
};
class CommonImplementation : public BaseInterface
{
public:
void f1() {}
};
class X : public DerivedInterface, public CommonImplementation
{
public:
void f2() {}
};

Dec 10 '05 #2
Matthias wrote:
If I change it to the following tree it works... Why does the first
method fail?
[..]


Because you can only override a virtual function (introduce the final
overrider) in a _descendant_ class, not sideways.

V
Dec 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Shawn Casey | last post by:
Consider the following code: interface IBase { virtual void BaseFunction() = 0; }; interface IDerived : public IBase { virtual void DerivedFunction() = 0;
6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
3
by: marv | last post by:
If I have abstract base classes like these: //--------- class IBase { public: virtual void Action(void) = 0; };
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
14
by: Bruno van Dooren | last post by:
Hi all, i am having a problems with inheritance. consider the following: class A { public: A(int i){;} };
8
by: mmu2643 | last post by:
Hi, I had a question regarding multiple inheritance. class B1{ public: int a; };
7
by: shintu | last post by:
Hi, For the following code snippet, the compiler complains for "mi *mi1=new mi;" statement //******************************************************* #include <iostream> using namespace std;...
2
by: Heinz Ketchup | last post by:
Hello, I'm looking to bounce ideas off of anyone, since mainly the idea of using Multiple Virtual Inheritance seems rather nutty. I chalk it up to my lack of C++ Experience. Here is my...
8
by: weird0 | last post by:
Can anyone explain briefly what is the difference between inheritance and polymorphism? i read and seem to forget it again and again... Can anyone along with good examples of c# explain the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.