<分区>
Possible Duplicate:
What are Aggregates and PODs and how/why are they special?
C++11 中的结构必须使用什么样的构造函数才能将此结构保留为 POD?
只接受初始化列表?或者也许没有任何限制?
<分区>
Possible Duplicate:
What are Aggregates and PODs and how/why are they special?
C++11 中的结构必须使用什么样的构造函数才能将此结构保留为 POD?
只接受初始化列表?或者也许没有任何限制?
最佳答案
你需要一个默认的默认构造函数,这样它就很简单了:
struct pot
{
constexpr pot() noexcept = default;
pot(int a, float b) : x(a), y(b) { }
int x;
float y;
};
constexpr
和 noexcept
是可选的,但我们也可以。
用法:
pot p; // OK
pot q(1, 1.5); // also OK
关于c++ - C++11 中对 POD 的构造函数要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12228698/