此代码编译失败:
unordered_map<char, int[4]> inv = {
{ 'a', {{0,0,1,0}} }
}
当作为类型参数传递时,初始化此 int 数组的正确方法是什么?
我试过:int[]
, array<int,4>
但他们都给出了错误:
no instance of constructor "std::unordered_map<_Kty, _Ty, _Hasher,
_Keyeq, _Alloc>::unordered_map [with _Kty=char, _Ty=std::pair<Cell *, int []>, _Hasher=std::hash<char>, _Keyeq=std::equal_to<char>,
_Alloc=std::allocator<std::pair<const char, std::pair<Cell *, int []>>>]" matches the argument list
最佳答案
这应该有效:
#include <array>
std::unordered_map<char, std::array<int, 4>> inv = {{ 'a', {{0, 0, 1, 0}} }};
关于c++ - 将 int 数组初始化为类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138390/