1.函数返回值为static类型,函数内部有static变量
#include "stdafx.h"
#include <iostream>
using namespace std;
class test {
private:
int i;
static int get_i(){
static int test_a = 2;
test_a++;
return test_a;
}
public:
test():i( get_i()) {
}
int get_out_i(){
return i;
}
~test(){
cout <<"over" <<endl;
}
};
int main()
{
test a;
cout <<"a i=" <<a.get_out_i()<<endl;
test b;
cout <<"b i=" <<b.get_out_i() <<endl;
test c;
cout <<"c i=" <<c.get_out_i() <<endl;
return 1;
}
运行结果:
2.函数返回值不是static类型,函数内部有static变量
程序运行结果和1 一样
3.函数返回值是static类型,函数内部不是static变量
运行结果为: