c**********e 发帖数: 2007 | 1 class A
{
public: int x;
protected: int y;
private: int z;
};
class B: private A
{
B(int x_, int y_, int z_) {
x=x_; y=y_; z=z_;
};
Question (Selection)
a. The constructor cannot initialize any of the variables inherited from "A"
because they have all been made private.
b. The constructor cannot initialize member variable "z" because it is
private in A. |
I*****y 发帖数: 602 | 2 b.
【在 c**********e 的大作中提到】 : class A : { : public: int x; : protected: int y; : private: int z; : }; : class B: private A : { : B(int x_, int y_, int z_) { : x=x_; y=y_; z=z_;
|
j***i 发帖数: 1278 | 3 A, private inheritance 所有的member都是private
【在 c**********e 的大作中提到】 : class A : { : public: int x; : protected: int y; : private: int z; : }; : class B: private A : { : B(int x_, int y_, int z_) { : x=x_; y=y_; z=z_;
|
d****p 发帖数: 685 | 4 private inheritance means the sub-object of base class is a private "member"
in derived class object - the derived class object itself can still access
any non-private members of the sub-object.
B is right.
【在 j***i 的大作中提到】 : A, private inheritance 所有的member都是private
|
j***i 发帖数: 1278 | 5 谢谢 指导, 想清楚概念了
member"
access
【在 d****p 的大作中提到】 : private inheritance means the sub-object of base class is a private "member" : in derived class object - the derived class object itself can still access : any non-private members of the sub-object. : B is right.
|
j***i 发帖数: 1278 | 6 你这么一说,我是糊涂了,
不过我编译了一下,确实是decamp说的那羊
望大牛们继续指点 |
E*U 发帖数: 2028 | |
t****t 发帖数: 6806 | 8 等等, sorry, 我看错他说的意思了. 他说的是对的.
【在 j***i 的大作中提到】 : 你这么一说,我是糊涂了, : 不过我编译了一下,确实是decamp说的那羊 : 望大牛们继续指点
|
d*****d 发帖数: 46 | 9 An advantage of private inheritance over composition is that the former can
have base class protected member access.
【在 j***i 的大作中提到】 : A, private inheritance 所有的member都是private
|
d****p 发帖数: 685 | 10 Finally found this :-)
11.2 If a class is declared to be a base class (clause 10) for another class
using the public access specifier, the public
members of the base class are accessible as public members of the derived
class and protected members of the base
class are accessible as protected members of the derived class. If a class
is declared to be a base class for another
class using the protected access specifier, the public and protected members
of the base class are accessible as
protected
【在 t****t 的大作中提到】 : 等等, sorry, 我看错他说的意思了. 他说的是对的.
|
|
|
E*U 发帖数: 2028 | 11 from c++ primer ?
class
members
base
【在 d****p 的大作中提到】 : Finally found this :-) : 11.2 If a class is declared to be a base class (clause 10) for another class : using the public access specifier, the public : members of the base class are accessible as public members of the derived : class and protected members of the base : class are accessible as protected members of the derived class. If a class : is declared to be a base class for another : class using the protected access specifier, the public and protected members : of the base class are accessible as : protected
|
j***i 发帖数: 1278 | 12 standard 把
【在 E*U 的大作中提到】 : from c++ primer ? : : class : members : base
|
I*****y 发帖数: 602 | 13 记得c++ FAQ(不是c++ FAQ书,而是网上的一个版本)里面有提到。
【在 E*U 的大作中提到】 : from c++ primer ? : : class : members : base
|
c**********e 发帖数: 2007 | 14 Thanks decamp for finding the standard.
Yes, class B : private A {} means that public/protected members
in A becomes private members in B. They are accessible in B.
【在 d****p 的大作中提到】 : Finally found this :-) : 11.2 If a class is declared to be a base class (clause 10) for another class : using the public access specifier, the public : members of the base class are accessible as public members of the derived : class and protected members of the base : class are accessible as protected members of the derived class. If a class : is declared to be a base class for another : class using the protected access specifier, the public and protected members : of the base class are accessible as : protected
|
l******e 发帖数: 12192 | 15 brainbench? hehe
【在 c**********e 的大作中提到】 : class A : { : public: int x; : protected: int y; : private: int z; : }; : class B: private A : { : B(int x_, int y_, int z_) { : x=x_; y=y_; z=z_;
|
r********3 发帖数: 2998 | 16 这点跟Java不太一样。
还是觉得Java设计得更合理一些 |
P********e 发帖数: 2610 | 17 你彻底把这里农火了,赞啊
【在 c**********e 的大作中提到】 : class A : { : public: int x; : protected: int y; : private: int z; : }; : class B: private A : { : B(int x_, int y_, int z_) { : x=x_; y=y_; z=z_;
|
p****o 发帖数: 1340 | 18 i think java is the same as c++ here... any other folks think otherwise?
【在 r********3 的大作中提到】 : 这点跟Java不太一样。 : 还是觉得Java设计得更合理一些
|
r********3 发帖数: 2998 | 19 Java的话,父类的private成员变量,子类是不能访问的。
【在 p****o 的大作中提到】 : i think java is the same as c++ here... any other folks think otherwise?
|
p****o 发帖数: 1340 | 20 the same here, am i right? B cannot access z since it is private in A.
【在 r********3 的大作中提到】 : Java的话,父类的private成员变量,子类是不能访问的。
|