- 论坛徽章:
- 2
|
回复 #11 aaaaal 的帖子
我还是好心把以前的帖子搜出来吧……
http://bbs.chinaunix.net/viewthread.php?tid=1473750#pid10665029
以下是对以前发帖的补充。
C++标准有一整章(11 Member access control)是讲这个的。
下面是一部分:
A member of a class can be
— private; that is, its name can be used only by members and friends of the class in which it is
declared.
— protected; that is, its name can be used only by members and friends of the class in which it is
declared, and by members and friends of classes derived from this class (see 11.5).
— public; that is, its name can be used anywhere without access restriction.
c_string_ 是MyString的一个private成员。它的名字只能被MyString的成员和友元使用。
复制构造函数是MyString的一个“成员(函数)”, 该成员函数能使用c_string_这个名字并没有什么不合理之处。
《The C++ Programming Language》中的描述似乎更好一些:
15.3 Access Control [hier.access]
A member of a class can be p r i v a t e , p r o t e c t e d , or p u b l i c :
– If it is p r i v a t e , its name can be used only by member functions and friends of the class in
which it is declared.
– If it is p r o t e c t e d , its name can be used only by member functions and friends of the class in
which it is declared and by member functions and friends of classes derived from this class
(see §11.5).
– If it is p u b l i c , its name can be used by any function.
更加强调了, 访问级限制的是函数。 |
|