#include using namespace std;

class Sample{ private: int x; static int y; public: Sample(int); void print(); };

Sample::Sample(int a){ x = a; y++; } void Sample::print(){ cout << 'x = ' << x << ', y = ' << y << endl; }

int Sample::y = 25;

int main(){ Sample s1(5); Sample s2(10); s1.print(); s2.print(); Sample::y = 27; //(1) s1.print(); s2.print(); system("pause"); return 0; }

C++程序填空:静态成员变量与类成员函数

原文地址: https://www.cveoy.top/t/topic/oX5S 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录