扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
#include<iostream> using namespace std; class B { public: int f(int i) { cout << "f(int): "; return i+1; } // ... }; class D : public B { public: double f(double d) { cout << "f(double): "; return d+1.3; } // ... }; int main() { D* pd = new D; cout << pd->f(2) << ’\n’; cout << pd->f(2.3) << ’\n’; } |
f(double): 3.3 f(double): 3.6 |
f(int): 3 f(double): 3.6 |
class D : public B { public: using B::f; // make every f from B available double f(double d) { cout << "f(double): "; return d+1.3; } // ... }; |
f(int): 3 f(double): 3.6 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。