且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么复制构造函数隐藏了C ++中的默认构造函数?

更新时间:2022-11-23 21:51:16

默认构造函数只有生成如果你不声明任何构造函数。假设如果你定义自己的构造函数,那么你还可以决定是否需要一个无参数的构造函数,如果这样定义的话。

The default constructor is only generated if you don't declare any constructors. It's assumed that if you're defining a constructor of your own, then you can also decide whether you want a no-args constructor, and if so define that too.

在C ++ 0x,会有一个明确的语法,说你想要的默认构造函数:

In C++0x, there will be an explicit syntax for saying you want the default constructor:

struct Foo {
    Foo() = default;
    ... other constructors ...
};