码迷,mamicode.com
首页 > 编程语言 > 详细

Private Inheritance for C++

时间:2017-06-05 10:35:01      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:prime   prot   cond   derived   can   let   short   objects   interface   

  C++ has a second means of implementing the has-a relationship: private inheritance.With private inheritance, public and protected members of the base class become private members of the derived class.This means the methods of the base class do not become part of the public interface of the derived object.They can be used, however, inside the member functions of the derived class.
Let’s look at the interface topic more closely.With public inheritance, the public methods of the base class become public methods of the derived class. In short, the derived class inherits the base-class interface.This is part of the is-a relationship.With private inheritance, the public methods of the base class become private methods of the derived class. In short, the derived class does not inherit the base-class interface.As you saw with contained objects, this lack of inheritance is part of the has-a relationship.  

                                                            from 《c++ primer plus》 

Private Inheritance for C++

标签:prime   prot   cond   derived   can   let   short   objects   interface   

原文地址:http://www.cnblogs.com/aceg/p/6942637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!