由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Q01: private inheritance.
相关主题
what is the difference?c++问题,请高人指点迷津,c++ faq lite的一个例子
protected class member in C++C++ 中 myobject * a =new myobject[n] 的问题
一道 memset in C++的题Test your C++ knowledge...
one question about structC++: exception: out-of-order execution?
抠字眼:assignment and initialize in C++找工作被要求做ikmnet.com 的在线C++考试,请问怎么准备?
c++ initialize struct[合集] 一些C++问题
pthread_create inside a constructor请教问题
问个copy constructor的问题C++ 什么时候用 "new" ?
相关话题的讨论汇总
话题: private话题: class话题: int话题: members话题: protected
进入Programming版参与讨论
1 (共1页)
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
7
.....
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, 我看错他说的意思了. 他说的是对的.
相关主题
c++ initialize structc++问题,请高人指点迷津,c++ faq lite的一个例子
pthread_create inside a constructorC++ 中 myobject * a =new myobject[n] 的问题
问个copy constructor的问题Test your C++ knowledge...
进入Programming版参与讨论
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成员变量,子类是不能访问的。
1 (共1页)
进入Programming版参与讨论
相关主题
C++ 什么时候用 "new" ?抠字眼:assignment and initialize in C++
find bugs of c++ codesc++ initialize struct
Is the order of initialization a, b, c or c, b, a?pthread_create inside a constructor
一个 default constructor 的问题问个copy constructor的问题
what is the difference?c++问题,请高人指点迷津,c++ faq lite的一个例子
protected class member in C++C++ 中 myobject * a =new myobject[n] 的问题
一道 memset in C++的题Test your C++ knowledge...
one question about structC++: exception: out-of-order execution?
相关话题的讨论汇总
话题: private话题: class话题: int话题: members话题: protected