#include <iostream>
struct A {
virtual void run( ) const = 0 ;
} ;
struct B : public A {
// uncomment the following line to make the code work
// using A::run;
virtual void run( int ) const = 0 ;
} ;
struct C : public B {
void run( ) const override {
std:: cout << "implementation of A::run\n " ;
}
} ;
struct D : public C {
void run( int ) const override {
std:: cout << "implementation of B::run\n " ;
}
} ;
struct E : public D { } ;
int main( ) {
const B& obj = E{ } ;
obj.run ( ) ; // not visible to the compiler in the overload set
obj.run ( 5 ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEEgewoJdmlydHVhbCB2b2lkIHJ1bigpIGNvbnN0ID0gMDsKfTsKCnN0cnVjdCBCIDogcHVibGljIEEgewogICAgLy8gdW5jb21tZW50IHRoZSBmb2xsb3dpbmcgbGluZSB0byBtYWtlIHRoZSBjb2RlIHdvcmsKICAgIC8vIHVzaW5nIEE6OnJ1bjsKCXZpcnR1YWwgdm9pZCBydW4oaW50KSBjb25zdCA9IDA7Cn07CgpzdHJ1Y3QgQyA6IHB1YmxpYyBCIHsKCXZvaWQgcnVuKCkgY29uc3Qgb3ZlcnJpZGUgewoJCXN0ZDo6Y291dCA8PCAiaW1wbGVtZW50YXRpb24gb2YgQTo6cnVuXG4iOwoJfQp9OwoKc3RydWN0IEQgOiBwdWJsaWMgQyB7Cgl2b2lkIHJ1bihpbnQpIGNvbnN0IG92ZXJyaWRlIHsKCQlzdGQ6OmNvdXQgPDwgImltcGxlbWVudGF0aW9uIG9mIEI6OnJ1blxuIjsKCX0KfTsKCnN0cnVjdCBFIDogcHVibGljIEQge307CgppbnQgbWFpbigpIHsKCWNvbnN0IEImIG9iaiA9IEV7fTsKCW9iai5ydW4oKTsgLy8gbm90IHZpc2libGUgdG8gdGhlIGNvbXBpbGVyIGluIHRoZSBvdmVybG9hZCBzZXQKICAgIG9iai5ydW4oNSk7CglyZXR1cm4gMDsKfQ==
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:10: error: no matching function for call to ‘B::run() const’
obj.run(); // not visible to the compiler in the overload set
^
prog.cpp:10:15: note: candidate: ‘virtual void B::run(int) const’
virtual void run(int) const = 0;
^~~
prog.cpp:10:15: note: candidate expects 1 argument, 0 provided
stdout