Possible Duplicate:
Implementing abstract class members in a parent class
Why does C++ not let baseclasses implement a derived class' inherited interface?
Considering these objects:
struct A
{
virtual void foo() = 0;
};
struct B
{
void foo() { /* neat implementation */ }
};
I wonder why --compiler-wise-- the following object is considered abstract:
struct C : B, A
{
using B::foo; // I tried my best to make the compiler happy
};
The compiler won't let me do this:
A* a = new C;
Visual Studio 2010 says:
'C' : cannot instantiate abstract class due to following members: 'void A::foo(void)' : is abstract : see declaration of 'A::foo'
g++ 4.6.3 says:
cannot allocate an object of abstract type ‘C’ because the following virtual functions are pure within ‘C’: virtual void A::foo()
I guess this is allowed in C#, but I don't know the involved mecanism(s) -- I am just being curious.
Unfortunately, this does not quite do what you want.
A using
directive is just about bringing some names into the scope it is used. virtual
methods need be overriden, and just bringing names is not considered overriding.
The truth of the matter is that C++ does not support delegation directly. There is just this slight twist of bringing names into scope explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With