Redian新闻
>
public and protected member in private inherit
avatar
public and protected member in private inherit# Programming - 葵花宝典
i*p
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; } int Der1GetPubStat() { return pub_stat; } };
class Default_Der2 : Default_Der1
{
int Der2GetProStat() { return pro_stat; } int Der2GetPubStat() { return pub_stat; } };
avatar
b*n
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

avatar
i*p
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。