C + + 标准(第8.5节)说:
如果程序要求默认初始化一个固定类型 t 的对象,那么 t 应该是一个带有用户提供的缺省构造函数的类类型。
为什么? 我想不出在这种情况下为什么需要用户提供的构造函数。
struct B{
B():x(42){}
int doSomeStuff() const{return x;}
int x;
};
struct A{
A(){}//other than "because the standard says so", why is this line required?
B b;//not required for this example, just to illustrate
//how this situation isn't totally useless
};
int main(){
const A a;
}