首页 > 编程语言 > 详细

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

时间:2014-12-23 12:13:03      阅读:264      评论:0      收藏:0      [点我收藏+]
#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 C++ .33 子类的名称覆盖

原文:http://www.cnblogs.com/lailailai/p/4179673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!