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) is 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... - Constructorpublic 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. - DumbCoderNonPureVirtual
is abstract. - Kiril KirovPureVirtual
is that you're only affecting the scope/accessibility ofFunctionImpl::Function
withusing
; you're not overriding anything. - Simple