posts - 0,  comments - 0,  trackbacks - 0
class CBase
{
   public print();
};
如果子类私有或保护继承自基类,那么此时子类的对象是不能调用基类公有的成员的。
class CChild : private CBase
{
}
void main()
{
   CChild child;
   child.print();//此时的print()为私有的,child 就不能调用
}
=====================================================
但是用using在子类中声明基类的公有成员后,此成员在子类中认为共有,可以访问。
class CChild : private CBase
{
public:
   using CBase::print();
}
void main()
{
   CChild child;
   child.print();
}
posted on 2012-11-16 15:20 HiHi..! 阅读(95) 评论(0)  编辑 收藏 引用 所属分类: c++

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理