Consider following example
#include <iostream>
struct PureVirtual {
virtual void Function() = 0;
};
struct FunctionImpl {
virtual void Function() {
std::cout << "FunctionImpl::Function()" << std::endl;
}
};
struct NonPureVirtual : public FunctionImpl, public PureVirtual {
using FunctionImpl::Function;
};
int main() {
NonPureVirtual c;
c.Function();
}
Compiler (GCC 4.9, Clang 3.5) exits with error
test.cpp:18:20: error: variable type 'NonPureVirtual' is an abstract class
NonPureVirtual c;
^
test.cpp:4:18: note: unimplemented pure virtual method 'Function' in 'NonPureVirtual'
virtual void Function() = 0;
^
But when I don't derive form PureVirtual
everything is OK. This is weird because Standard 10.4.4 says
A class is abstract if it contains or inherits at least one pure virtual function for which the final overrider is pure virtual.
They are not saying anything about what the final overrider is but I suppose it should be FunctionImpl::Function()
especially when I made it available through using
directive. So why is still NonPureVirtual
abstract class and how can I fix this.
PureVirtual
is not the base ofFunctionImpl
, so... – Sargepublic FunctionImpl, public PureVirtual
->Function
is visible through both classes and specifically from PureVirtual, no virtual inheritance, so it makes it an abstract class. A guess. – DresselNonPureVirtual
is abstract. – Kimmyvirtual
inheritance only when you have the "diamond inheritance" - this is different case. – KimmyNonPureVirtual
is not an ABC when you don't have a pure virtual function. – PenetratePureVirtual
is that you're only affecting the scope/accessibility ofFunctionImpl::Function
withusing
; you're not overriding anything. – Penetrate/* virtual */ void Function() { FunctionImpl::Function(); }
inNonPureVirtual
but I have no idea if this is well defined. Most probably - not. – KimmyPureVirtual
base ofFunctionImpl
.. – Kimmyoverride
keyword in Overriding Virtual Functions. It also highlights some unexpected pitfalls related to differing default parameters in base and derived classes. – Collings