By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,614 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Multiple inheritance, dominance and pure base class

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.