#include <iostream>
#include <conio.h>
using namespace std;
class Base
{
int a;
public:
Base(const Base & b)
{
cout<<"inside constructor"<<endl;
}
};
int main()
{
Base b1;
getch();
return 0;
}
这会产生错误。没有匹配的函数来调用“Base::Base()”
为什么?
仅当您未声明任何构造函数时才会生成默认构造函数。假设如果您定义自己的构造函数,那么您还可以决定是否需要无参数构造函数,如果需要,也可以定义它。
在 C++0x 中,将有一个显式语法来表示您想要默认构造函数:
struct Foo {
Foo() = default;
... other constructors ...
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)