为什么要d.f(1)调用Derived::f此代码?
是否using Base::f决定其发挥作用f将被调用?
#include <iostream>
using namespace std;
struct Base {
void f(int){
cout << "\n f(Base) is called" ;
}
};
struct Derived : Base {
using Base::f ; // using-declarations but still Drived function is called
void f(int){
cout << "\n f(Derived) is called" ;
}
};
void use(Derived d)
{
d.f(1); // calls Derived::f
Base& br = d ;
br.f(1); // calls Base::f
}
int main() {
Derived d;
use (d);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
124 次 |
| 最近记录: |