家里有几块 屯的 主板。 大牛看看能值多少钱# Hardware - 计算机硬件
L*e
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
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