<分区>
在默认构造函数的定义中,= default;
是否与 { }
完全相同?在某些情况下它们可能具有不同的含义吗?
示例伪代码:
template<typename... Args>
struct S // maybe with base classes
{
S() = default;
// S() {} - same or different?
// other stuff...
};
<分区>
在默认构造函数的定义中,= default;
是否与 { }
完全相同?在某些情况下它们可能具有不同的含义吗?
示例伪代码:
template<typename... Args>
struct S // maybe with base classes
{
S() = default;
// S() {} - same or different?
// other stuff...
};
最佳答案
它们是不同的。通过 S() {}
,S
被认为具有用户提供的构造函数,而 S() = default;
则没有。例如,这会导致 S
是否符合聚合类型的条件。参见 here .
关于c++ - 对于构造函数,{} 是否与 =default 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29483044/