#include"iostream.h"
class A
{
public:
A(int y){d=y;}
void print_a(){cout<<a<<d<<endl;}
private:
static int a;//静态私有数据
protected:
int d;
};
int A::a=10;
class B:public A
{
public:
B(int x,int z):A(x){b=z;c=z*d;}
void print_b(){cout<<a<<b<<c<<endl;} //为什么不报错?
private:
int b;
protected:
int c;
};
int main()
{
B d(100,20);
d.print_a();
d.print_b();
}
程序正常运行,可是a是基类的私有成员变量,继承类却可以访问它,不知道为什么,难道静态成员例外?
[此贴子已经被作者于2006-9-26 19:34:07编辑过]