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
|