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

你可能感兴趣的:(effective)