#include <iostream>
using namespace std;
//4、写一个类,包括一些数据成员,还有静态成员num,用于记录个数,有静态函数getHowMuch()返回实例化的个数
class test{
public:
int test01;
test(){
num++;
}
test(int a){
test01 = a;
num++;
}
static int getHowMuch(){
return num;
}
private:
static int num;
};
int test::num=0;
int main()
{
test t1;
test t2(3);
int nums = test::getHowMuch();
cout << nums << endl;
return 0;
}
c++ 写一个类,包括一些数据成员,还有静态成员num,用于记录个数,有静态函数getHowMuch()返回实例化的个数
最新推荐文章于 2024-08-30 16:00:44 发布