#include <iostream>
#include <string>
#include <array>
class C {
private:
std::string a;
std::string b;
std::string c;
public:
C(std::string a_, std::string b_, std::string c_) : a{a_},b{b_},c{c_} {}
~C(){};
C(const C&) =delete;
C(const C&&) =delete;
const C& operator=(const C&) =delete;
const C& operator=(const C&&) =delete;
};
std::array<C,2> array = {C("","",""),C("","","")};
int main()
{}
这将不会编译(Android Studio与NDK和铿锵)与“调用删除C构造函数”错误。我知道我可以使用std::vector
和emplace_back()
直接在容器内构建元素,但在我的代码中,我只想使用固定大小的容器和不可复制/可移动的对象进行优化。我可能在这里缺少基本的东西,但是没有办法初始化std::array
而无需先构建单个元素然后将它们复制到那里?初始化std :: array没有复制/移动元素
通过你不需要把这些下划线在参数名的方式。 'C(std :: string a,std :: string b,std :: string c):a {a},b {b},c {c} {}'没有歧义问题,并且符合您的期望。 – nwp