首页 > 编程语言 > 详细

name hiding in C++

时间:2015-03-04 02:02:10      阅读:184      评论:0      收藏:0      [点我收藏+]

name hiding in C++

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdint.h>
#include <pthread.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
class A {
public:
    void fun() {
        cout << __PRETTY_FUNCTION__ << endl;
    }
    void fun(int x) {
        cout << __PRETTY_FUNCTION__ << endl;
    }
};
class B: public A {
public:
    //using A::fun; //solution 3
    void fun(int x) {
        cout << __PRETTY_FUNCTION__ << endl;
    }
};
int main(int argc, char* argv[]) {
    B b;
    //b.fun();//compile error, name hiding occurs
    b.A::fun(); //solution 1
    A* pa = &b;
    pa->fun();  //solution 2
    return 0;
}

name hiding in C++

原文:http://www.blogjava.net/bacoo/archive/2015/03/03/423156.html

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