此代码无法编译:
unordered_map<char, int[4]> inv = {
{ 'a', {{0,0,1,0}} }
}
Run Code Online (Sandbox Code Playgroud)
作为类型参数传递时,初始化此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
Run Code Online (Sandbox Code Playgroud)
这应该工作:
#include <array>
std::unordered_map<char, std::array<int, 4>> inv = {{ 'a', {{0, 0, 1, 0}} }};
Run Code Online (Sandbox Code Playgroud)