神奇的c++特性:using 改变访问级别
2012-08-18 15:31
495 查看
using change access level
Originally, the member function size() in class derived 's access level is private, but the using change it to public
using also can solve the problem that derived class can't overload base class's member(reference C++ PRIMER 15.5.3)
Originally, the member function size() in class derived 's access level is private, but the using change it to public
using also can solve the problem that derived class can't overload base class's member(reference C++ PRIMER 15.5.3)
#include <iostream> struct Base { int memfcn() { return 1; } }; struct Derived:Base { public: using Base::memfcn;//withnot "using ...",we can't access Derived::memfcn() int memfcn(int)//it will make Derived class hide the base's member memfcn // within the scope of the Derived class { return 2; } }; struct child:Derived { }; int main() { Derived d; Base b; b.memfcn(); d.memfcn(10); std::cout<<d.memfcn()<<std::endl; std::cout<<d.Base::memfcn()<<std::endl; std::cout<<d.memfcn(2)<<std::endl; child ch; ch.memfcn(); return 0; }
相关文章推荐
- C++虚函数访问权限的改变
- C++ 子类能不能改变父类中成员的访问权限?
- 【C++】【一日一练】通过友元访问或改变类的私有成员【20140508】
- c++中的成员访问级别和派生继承方式
- C++ 继承类访问级别
- 继承中的三种访问级别——学习c++笔记
- [C++]类级别的访问修饰符 -- 由一道笔试题引起的一道破窗
- [转]c++类继承中的using声明,派生类中用using声明改变基类成员的访问权限
- C++语法基础--恢复继承成员的访问级别,默认继承保护级别,友元关系与继承,继承与静态成员
- C++中类的继承访问特性
- How to change the background color of form using C++ - 如何用C++改变窗体的颜色
- C++中的访问级别
- c++类继承中的using声明,派生类中用using声明改变基类成员的访问权限
- c++类继承中的using声明,派生类中用using声明改变基类成员的访问权限[zz]
- C++中的访问级别
- C++ 与 java 访问级别的不同
- How to access database using C++ & ADO - 如何用C++和ADO访问数据库
- 【C++深度剖析教程23】继承中的访问级别
- C++ 中类的访问级别控制(public,protected,private!~~~3p)
- 使用Mono.Cecil改变访问级别