由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - public and protected member in private inherit
相关主题
问一个inheritance的初级问题C++ private inheritance. v.s. composition
C++ Q01: private inheritance.java error 新手问题, 请帮忙看看
请问C++小白问题java error 新手问题, 请帮忙看看
C++ Q96: function inheritance (转载)error of sql query in MS Access database (转载)
protected class member in C++虚函数access权限改变问题
一个让我比较困惑的问题 c++ inheritenceask a C++ inheritance question
关于 exception 的一个问题protected/private inheritance
question on template and inheritance?C++ Primer 上关于inheritance protected member 的一段话
相关话题的讨论汇总
话题: stat话题: int话题: default话题: base话题: der1
进入Programming版参与讨论
1 (共1页)
i**p
发帖数: 902
1
They are accessible in the 1st inheritence, but not in 2nd (see error in the
following code). What reason made C++ designed this way?
class Base
{
protected:
int pro_stat;
public:
int pub_stat;
};
class Default_Der1 : Base
{
int Der1GetProStat() { return pro_stat; } <- Ok
int Der1GetPubStat() { return pub_stat; } <- Ok
};
class Default_Der2 : Default_Der1
{
int Der2GetProStat() { return pro_stat; } <- Error
int Der2GetPubStat() { return pub_stat; } <- Error
};
b********n
发帖数: 609
2
因为你private inherite了Base,那么Base的东西对Der1来说是可以access的,但对De
r2来说他们就是Der1的private的东东。

the

【在 i**p 的大作中提到】
: They are accessible in the 1st inheritence, but not in 2nd (see error in the
: following code). What reason made C++ designed this way?
: class Base
: {
: protected:
: int pro_stat;
: public:
: int pub_stat;
: };
: class Default_Der1 : Base

i**p
发帖数: 902
3
It seems what you said is logically. However in Java, the compiler won’t
let you decrease the access of a member during inheritance.

De

【在 b********n 的大作中提到】
: 因为你private inherite了Base,那么Base的东西对Der1来说是可以access的,但对De
: r2来说他们就是Der1的private的东东。
:
: the

1 (共1页)
进入Programming版参与讨论
相关主题
C++ Primer 上关于inheritance protected member 的一段话protected class member in C++
考考大家,其实也不只是C++,C#/Java也一样一个让我比较困惑的问题 c++ inheritence
inheritence problem关于 exception 的一个问题
两个看来相似的问题question on template and inheritance?
问一个inheritance的初级问题C++ private inheritance. v.s. composition
C++ Q01: private inheritance.java error 新手问题, 请帮忙看看
请问C++小白问题java error 新手问题, 请帮忙看看
C++ Q96: function inheritance (转载)error of sql query in MS Access database (转载)
相关话题的讨论汇总
话题: stat话题: int话题: default话题: base话题: der1