由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ protected base class
相关主题
长期提供Twitter内推现在不会java,不会C#是不是很不好找工作了啊
再问一个碰到的C++问题从没什么programming基础,到学会SAS base要多久?
算法博客更新说说flextrade 的 onsite 经历
consulting needed for Android based programing芝加哥西北郊区, 7.2W可以接受吗?
关于multithread programming大家看什么书看programming pearl进行时的感想
VBA Programming 的前景怎么样?请问用什么书学习Java和windowsAPI最好?
读书计划没有经验也ok
求 Programming Pearls (2nd Edition) 全本请教:embedded C
相关话题的讨论汇总
话题: class话题: base话题: y2话题: py2话题: z2
进入JobHunting版参与讨论
1 (共1页)
L*******e
发帖数: 114
1
Here is the code snippet from C++ programing language book. What confused me
is the statement "px = py2", the book says an error "we do not know that
py2 is a Z2 or how Y2::x is used in an non-Z2 object", but g++ did not
complain.
Did I misread something?
class X{
public:
int a;
};
class Y1 : public X {};
class Y2 : protected X {};
class Y3 : private X {};
class Z2 : public Y2 {
void f(Y1* py1, Y2* py2, Y3* py3)
{
X *px = py1; // X is a public base of Y1
py1->a = 7
j***i
发帖数: 1278
2
I think px=py2 should be fine, py2 is the argument Y2 obj's ptr
do not related to Z2 , and px->a=7 is also fine, since the access check is
static, px is X* so a is accessible

me

【在 L*******e 的大作中提到】
: Here is the code snippet from C++ programing language book. What confused me
: is the statement "px = py2", the book says an error "we do not know that
: py2 is a Z2 or how Y2::x is used in an non-Z2 object", but g++ did not
: complain.
: Did I misread something?
: class X{
: public:
: int a;
: };
: class Y1 : public X {};

x***y
发帖数: 633
3
I think this is an interesting problem for the conversion between
inheritence hiearachy.
class Base{};
class publicDerived: public Base{};
class protectedDerived: protected Base{};
class privateDerived: private Base{};
Base * pBase;
publicDerived * pPublic;
protectedDerived * pProtected;
privateDerived * pPrivate;
pBase = pPublic; // fine
pBase = pProtected; //error C2243: 'type cast' : conversion exists, but is
inaccessible
pBase = pPrivate; // error C2243: 'type cast' : conversion exists, but

【在 L*******e 的大作中提到】
: Here is the code snippet from C++ programing language book. What confused me
: is the statement "px = py2", the book says an error "we do not know that
: py2 is a Z2 or how Y2::x is used in an non-Z2 object", but g++ did not
: complain.
: Did I misread something?
: class X{
: public:
: int a;
: };
: class Y1 : public X {};

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教:embedded C关于multithread programming大家看什么书
C++ Developers in NY [转]VBA Programming 的前景怎么样?
问个算法题之被dynamic programming打败了读书计划
请教IKM Online C++考试求 Programming Pearls (2nd Edition) 全本
长期提供Twitter内推现在不会java,不会C#是不是很不好找工作了啊
再问一个碰到的C++问题从没什么programming基础,到学会SAS base要多久?
算法博客更新说说flextrade 的 onsite 经历
consulting needed for Android based programing芝加哥西北郊区, 7.2W可以接受吗?
相关话题的讨论汇总
话题: class话题: base话题: y2话题: py2话题: z2