在GCC中使用Brace Initializer初始化成员STD ::数组时错误
Error when initializing a member std::array with a brace initializer in gcc
考虑以下示例:
#include <array>
template <typename T>
struct A {
A() {}
};
typedef A<int> B;
struct S {
std::array<B, 1> b;
S() : b{{B()}} {}
};
int main() {
S s;
}
尝试用G 4.6.3和-std=c++0x
编译时,我会得到此错误:
test.cc: In constructor ‘S::S()’:
test.cc:13:16: error: no matching function for call to ‘std::array<A<int>, 1ul>::array(<brace-enclosed initializer list>)’
test.cc:13:16: note: candidates are:
/usr/include/c++/4.6/array:60:12: note: std::array<A<int>, 1ul>::array()
/usr/include/c++/4.6/array:60:12: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(const std::array<A<int>, 1ul>&)
/usr/include/c++/4.6/array:60:12: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::array<A<int>, 1ul>&’
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(std::array<A<int>, 1ul>&&)
/usr/include/c++/4.6/array:60:12: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::array<A<int>, 1ul>&&’
但是,定义变量时相同的支撑初始化可行:
std::array<B, 1> b{{B()}};
是因为GCC的特定版本没有完全实现C 11,或者我缺少某些内容,而第一个示例不正确?
是因为GCC的此特定版本未完全实现C 11
很可能是。GCC 4.6非常过时。
或我缺少一些东西,第一个示例不正确?
关于C 11语法,您的示例很好。它在Colliru上编译而没有错误或警告。
相关文章:
- std::ofstream 作为类成员删除复制构造函数?
- 使用 std::index_sequence 初始化具有固定大小数组成员的 POD 结构容器
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- 使用 std::async 时死锁,将来作为成员
- 可变参数模板参数扩展 类型为 std::function 的类成员
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- 为什么 std::sort 找不到合适的(静态成员)函数重载?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 在模板化成员函数的返回类型中使用 std::enable_if 时的编译器差异
- 有没有办法避免为 std::variant 类成员中的所有类型编写构造函数?
- 是否允许类类型的 std::function 成员变量(不完整类型)?
- 访问 std:vector 的类成员 std:vector 在一个类中与另一个 std:vector
- std::异步与非静态成员函数
- 如何在 c++11 中静态断言 std::array 类成员进行排序?
- 将初始化器列表/聚合初始化转发到 std::array 成员
- C++ IDE 不会推断/自动完成对模板类中的 std::array 下标表达式的成员访问
- 在哪里可以找到 std::bitset 的数据成员?
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- unique_ptr问题:不是'std'成员
- std::成员函数的异步调用