c++ - C++11 中对 POD 的构造函数要求

标签 c++ c++11

<分区>

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;
};

constexprnoexcept 是可选的,但我们也可以。

用法:

pot p;         // OK
pot q(1, 1.5); // also OK

关于c++ - C++11 中对 POD 的构造函数要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12228698/

相关文章:

c++ - 访问嵌套类模板的静态成员函数

c++ - 关于 std::array 的初始化

c++ - 使用尾随返回类型定义的函数的Doxygen行为

c++ - 在声明中合并两个常量 `std::set`(不是在运行时)

c++ - 索引集(用于在 vector 中有效删除)

c++ - Tic Tac Toe 覆盖数组用户输入

C++ 错误 : expected primary-expression before ‘.’ token

c++ - 如何从 std::vector 添加删除 std::functions

c++ - 模板多态性和unique_ptr

c++ - 发生了什么事:C++ std::move on std::shared_ptr 增加了 use_count?