Before asking, I had refer to this older question. But I have still queries.
struct B1 {
virtual void fun () = 0;
};
struct B2 {
void fun () { cout<<"B2::fun()\n"; }
void fun (int i) {}
};
struct D : B1, B2 {
using B2::fun; // This line doesn't help
};
int main ()
{
B1 *pB1 = new D; // Error: cannot allocate 'D' because 'B1::fun()' is abstract
pB1->fun();
}
- Any reason for C++ standard not accepting, inherited member functions to resolve
pure virtualmechanism ? - Why
usingkeyword doesn’t help resolving this error ? (compiler: linux-64 g++) - Which function is used for
usingkeyword,B2::fun()orB2::fun(int)? (there is no ambiguity for that line)
From ISO/IEC 14882:2003(E) 7.3.3.12
So, in the example you provided there is no ambiguity at all. Depending up on the parameter passed, call to a method can be decided.