#include <iostream>
using namespace std;
class Test{
private:
static int val;
int a;
public:
static int func();
static void sfunc(Test &r);
};
int Test::val=20;//在类外赋值静态数据
int Test::func()
{
val+=val; //val 自加
return val;
}
void Test::sfunc (Test &r)
{
r.a=25;
cout<<"Result3="<<r.a<<endl;//调用
}
int main(){
cout <<"Resultl="<<Test::func()<<endl; //调用静态函数,val自加为40,(静态函数不属于哪个对象故可以不需要对象
Test a;
cout<<"Result2="<<a.func()<<endl; //再次调用静态函数,有对象调用val自加为80
Test::sfunc (a); //
return 0;
}
第四周 阅读程序 6
