为什么std :: in_place_t的构造函数默认且显式?

时间:2019-03-18 15:56:50

标签: c++ std explicit explicit-constructor defaulted-functions

cppreference显示std::in_place_t的以下定义:

struct in_place_t {
    explicit in_place_t() = default;
};
inline constexpr std::in_place_t in_place{};

为什么他们添加了explicit并默认了构造函数?为什么不排除它?有什么好处?

2 个答案:

答案 0 :(得分:4)

如果省略构造函数,它将不会是explicit。如果您不= default,那将不会琐碎

因此,如果您希望构造函数为explicit,并且还希望它保持琐碎,那么您看到的是唯一可用的选项。

答案 1 :(得分:4)

您希望像这样的类型只能 <KSYVideo source={{ uri: "rtmp://184.72.239.149/vod/mp4:bigbuckbunny_1500.mp4" }} // Can be a URL or a local file. ref={ref => { this.player = ref; }} // Store reference volume={1.0} muted={false} paused={this.state.paused} // Pauses playback entirely. resizeMode="cover" // Fill the whole screen at aspect ratio.* repeat={true} // Repeat forever. playInBackground={false} background. progressUpdateInterval={250.0} style={{ height: 400 }} /> 可构造,因为在可能合理找到explicit的地方,它表示一种特殊的构造函数重载。

考虑以下结构

{}
相关问题