05_04.cpp
来自「一些C++的课件和实验源代码」· C++ 代码 · 共 33 行
CPP
33 行
// 05_04.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
class A{
public:
static int count; // 纪录总的对象个数
int id; // 纪录当前对象编号
A(){ id = ++count; }
void show(){
printf("\nobj%d id = %d count = %d",
id, id, count );
}
};
int A::count = 0; // 初始化静态成员
int main(int argc, char* argv[])
{
A a[3];
printf("count of class A is %d", A::count);
for(int i = 0; i < A::count; i++)
a[i].show();
getch();
return 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?