习题是关于static成员函数的
#include "stdafx.h"
#include "iostream"
using namespace std;
class Foo{
public:
Foo(int value)
{
a=value;
}
int geta()
{
return a;
}
int a;
};
class Bar{
public :
static int a;
static Foo f;
Foo FooVal()
{
callsFooVal++;
return f;
}
static int callsFooVal;
};
int Bar::a=0;
int Bar::callsFooVal=0;
Foo Bar::f=Foo(3);
int _tmain(int argc, _TCHAR* argv[])
{
Foo f(2);
Bar b;
f=b.FooVal();
cout<<b.callsFooVal;
system("pause");
return 0;
}
程序告诉我们,如果B类含有A类的一个对象,而A类的这个对象含有一个带参数的构造函数,在类B中,似乎并不需要直接将A的对象初始化