#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
时间: 2024-10-08 04:43:01