64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class A
{
public:
int a;
static int b;
void show(void)
{
cout <<"a=" <<a <<", b=" <<b <<",c=" <<c <<",d= " <<d<<endl;
}
private:
int c;
static int d;
};
int A::b = 5; //静态类型
int A::d = 10; //只有静态常量整型数据成员才可以在类中初始化
//本语句是为类中声明的成员提供定义。此时不受访问控制的约束,也就是说无所谓私有公有。
int main(void)
{
class A aa;
cout<<A::b<<endl; //这儿当然不能用cout<<A::d<<endl 了,因为A::d是私有变量
aa.show();
system("pause");
return 0;
}