由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Primer 上关于inheritance protected member 的一段话
相关主题
[合集] protected inheritance in C++one question about operator delete
关于 VC++ vitual, reload 和 derive的一个问题...c++ question
protected class member in C++C++含有指针成员的类
问一个inheritance的初级问题public and protected member in private inherit
ask a C++ inheritance questionc++里边protected member可以在自己所在类调用码?
C++ Q01: private inheritance.C++: protect dtor
protected/private inheritancedefault Specifier是什么?
考考大家,其实也不只是C++,C#/Java也一样Question on C++ Access Control (protected)
相关话题的讨论汇总
话题: item话题: object话题: bulk话题: protected话题: derived
进入Programming版参与讨论
1 (共1页)
B****S
发帖数: 597
1
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.
真是你妹啊。
t*****n
发帖数: 4908
2
技术牛人写书就是这风格。所以教书匠不一定是牛人,牛人不一定适合教书。

【在 B****S 的大作中提到】
: 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.
: 真是你妹啊。

B****S
发帖数: 597
3
C++出来的还是太早了,设计上面太多的否定之否定,什么情况都想cover。搞得细节太多。
技术牛人就是这种风格,以为其他人都和他一样牛。
别人还要干别的事情,又不是和他一样把所有时间都花在那个上面了。能帮助别人省时
间的才是牛人。

【在 t*****n 的大作中提到】
: 技术牛人写书就是这风格。所以教书匠不一定是牛人,牛人不一定适合教书。
t*****n
发帖数: 4908
4
这也不是缺点。每种语言都有垃圾冗余的地方。只看细节,没啥意思。语言就是来干活
的。

多。

【在 B****S 的大作中提到】
: C++出来的还是太早了,设计上面太多的否定之否定,什么情况都想cover。搞得细节太多。
: 技术牛人就是这种风格,以为其他人都和他一样牛。
: 别人还要干别的事情,又不是和他一样把所有时间都花在那个上面了。能帮助别人省时
: 间的才是牛人。

c*****n
发帖数: 75
5
〉〉“真是你妹啊”
这段话有什么问题吗?首先,你漏掉了这段话前的 "In Addition, protected has
another important property: A derived object...."
在结合书中这段话后面的的例子, 这段话的意思非常清楚了。并无冗余。
以下是摘要全段:
In addition, protected has another important property:
· 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.
As an example, let's assume that Bulk_item defines a member function that
takes a reference to a Bulk_item object and a reference to an Item_base
object. This function may access the protected members of its own object
as well as those of its Bulk_item parameter. However, it has no special
access to the protected members in its  Item_base parameter:
void Bulk_item::memfcn(const Bulk_item &d, const Item_base &b)
{
// attempt to use protected member
double ret = price; // ok: uses this->price
ret = d.price; // ok: uses price from a Bulk_item object
ret = b.price; // error: no access to price from an Item_base
}
The use of d.price is okay, because the reference to price is through an
object of type  Bulk_item. The use of b.price is illegal because Bulk_item
has no special  access to objects of type Item_base.
B****S
发帖数: 597
6
难道我的英语不过关?

only

【在 c*****n 的大作中提到】
: 〉〉“真是你妹啊”
: 这段话有什么问题吗?首先,你漏掉了这段话前的 "In Addition, protected has
: another important property: A derived object...."
: 在结合书中这段话后面的的例子, 这段话的意思非常清楚了。并无冗余。
: 以下是摘要全段:
: In addition, protected has another important property:
: · 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.
: As an example, let's assume that Bulk_item defines a member function that

m*******l
发帖数: 12782
7
clas != object

【在 B****S 的大作中提到】
: 难道我的英语不过关?
:
: only

l*********s
发帖数: 5409
8
还以为这本是给初学者用的,看来还是有点花头的。
B****S
发帖数: 597
9
理论上,c++ primer应该包括所有东西了,虽然细节未必面面俱到。

【在 l*********s 的大作中提到】
: 还以为这本是给初学者用的,看来还是有点花头的。
B****S
发帖数: 597
10
class里面函数还调用class本身的object,这种做法应该不值得推广把。很容易死循环
阿。

【在 m*******l 的大作中提到】
: clas != object
1 (共1页)
进入Programming版参与讨论
相关主题
Question on C++ Access Control (protected)ask a C++ inheritance question
C++子类中调用父类指针的问题C++ Q01: private inheritance.
C++ virtual function 问题protected/private inheritance
g++编译了不该过的C++代码考考大家,其实也不只是C++,C#/Java也一样
[合集] protected inheritance in C++one question about operator delete
关于 VC++ vitual, reload 和 derive的一个问题...c++ question
protected class member in C++C++含有指针成员的类
问一个inheritance的初级问题public and protected member in private inherit
相关话题的讨论汇总
话题: item话题: object话题: bulk话题: protected话题: derived