类:继承-4-静态成员
程序员文章站
2023-12-21 21:43:34
...
#include <iostream>
//
class A
{
public:
static int a;//静态成员变量只有唯一一份
int b;
};
int A::a = 0;
class B : public A
{
public:
int c;
void f()
{
A::a = 1;
}
};
void main()
{
std::cout<<sizeof(A) <<std::endl;//4
std::cout<<sizeof(B) <<std::endl;//8
system("pause");
}