源程序:
#include <iostream>
using namespace std;
class Test
{
private:
static int num;
public:
Test(int);
void show();
};
int Test::num = 5;
Test::Test(int n)
{
num = n;
}
void Test::show()
{
cout << num << endl;
}
int main()
{
Test t(10);
t.show();
system("pause");
return 1;
}
运行结果: