C++之Access Label, Inheritance, and Friend
2012-09-28 04:07
615 查看
************Inheritance************
Three modes of inheritance in C++: public, protected, private. For example: class D: public A, protected B, private C. (A, B, C, D are all class types)class B: public (protected, private) A
In all modes of inheritance, the private members of base class A remain PRIVATE to A and are NOT accessible from members of B.
When B inherits publically from A, the protected members of A become protected members of B, and the public members of A become public members of B.
When the inheritance mode is protected, both the public and protected members of A become protected members of B.
If the derivation mode is private, then the public and protected members of A become private in B.
************friend************
The friend mechanism allows a class to grant access to its nonpublic members to specified functions or classes.Friendship is not inherited.
************access control************
public members: The public section of a class defines members that can be accessed from any part of the program.private members: Codes that is NOT part of the class does not have access to the private members.
protected members:
Like private members, protected members are inaccessible to users of the class.
Like public members, protected members are accessible to classes derived from the class.
A derived object may access the protected members of its base class ONLY through a derived object. The derived class has no special access to the protected members of base type objects.
相关文章推荐
- (原創) C++的4個Class Access Label (C/C++)
- C++ Knowledge series Inheritance & RTTI & Exception Handling
- VS2010 C++学习(6): ListCtl用法及ADO方式读写Access程序
- 使用ADO连接ACCESS和SQL SERVER数据库[C++]
- 【C/C++】error: jump to case label
- 学习笔记之深入浅出MFC 第8章 C++重要性质----基类与派生类:谈继承(Inheritance)
- C++ 多继承和虚继承的内存布局(Memory Layout for Multiple and Virtual Inheritance)
- C++ 解决"Error: Jump to case label"的问题
- C++中Inheritance的使用
- <Qt C++>选择文件\选择文件夹\label播放gif
- C++ - 在容器(container)中 使用继承(inheritance)和虚函数(virtual function)
- SOCI - The C++ Database Access Library
- Class Inheritance in C++
- C++ derived class access specifier
- c++ inheritance -- 继承
- C++ 性能剖析 (四):Inheritance 对性能的影响
- C++ inheritance examples
- C++ - 在容器(container)中 使用继承(inheritance)和虚函数(virtual function)
- 【C++ 异常】error: jump to case label, crosses initialization
- Multiple Inheritance in C++