请教一个关于构造函数的问题
自己编译时,发现如下代码编译不过.
C2512. 如下是具体解释.
Error Message
'identifier' : no appropriate default constructor available
No default constructor is available for the specified class, structure, or union. The compiler supplies a default constructor if user-defined constructors are not provided.
If you provide a constructor that takes a non-void parameter, and you want to allow your class to be created with no parameters, you must also provide a default constructor. The default constructor can be a constructor with default values for all parameters.
class Foo
{
int tVar;
public:
Foo(int t) : tVar(t) { }
};
class FooDerived : public Foo{ };
int main(void)
{
FooDerived fd; //C2512
}
但是我修改后,编译通过. Foo(int t) : tVar(t) 这个不是父类的构造函数?
class Foo
{
int tVar;
public:
//Foo(int t) : tVar(t) { }
};
请问专家为什么? 多谢.