#include <iostream> using namespace std ; class Banana { public: static int id ; Banana(void) { id++ ; cout << "this is a test: " << id << endl ; } }; //类中的静态变量,必须在全局定义 int Banana::id = 0 ; int main(void) { Banana a , b , c , d , e , f , g; return 0 ; }
运行结果:
时间: 2024-10-14 23:34:27