Effective C++ .33 子类的名称覆盖

#include <iostream>
#include <cstdlib>

using namespace std;

class Base {
    public:
        int add(int a, int b) {
            return a + b;
        }
};

class Derived : public Base {
    public:
        using Base::add;
        int add(int a, int b, int c) {
            return a + b + c;
        }
};

int main() {

    Derived d;
    cout<<d.add(1, 2)<<endl;
    return 0;
}

如果不在Derived中加入using命令,那么在main中就不能调用两个参数的add

原文地址:https://www.cnblogs.com/lailailai/p/4179673.html