这是我的代码:
#include <array>
struct A
{
A(int) {}
};
std::array<A, 42> a;
int main()
{
return 0;
}
错误:
$ g++ -Wall -Wextra -Wpedantic main.cpp
main.cpp:9:19: error: use of deleted function `std::array<A, 42ul>::array()'
std::array<A, 42> a;
^
In file included from main.cpp:1:0:
/usr/include/c++/6/array:90:12: note: `std::array<A, 42ul>::array()' is implicitly deleted because the default definition would be ill-formed:
struct array
^~~~~
/usr/include/c++/6/array:90:12: error: no matching function for call to `A::A()'
main.cpp:5:5: note: candidate: A::A(int)
A(int) {}
^
main.cpp:5:5: note: candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr A::A(const A&)
struct A
^
main.cpp:3:8: note: candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr A::A(A&&)
main.cpp:3:8: note: candidate expects 1 argument, 0 provided
我的环境:
$ g++ --version
g++ (Debian 6.3.0-6) 6.3.0 20170205
相关:
为什么我预计这会起作用:
std::array
在创建时不会初始化其元素。 A
的大小定义明确。