M
Matthias
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
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