Reputation: 23178
This code fails to compile:
unordered_map<char, int[4]> inv = {
{ 'a', {{0,0,1,0}} }
}
What's the proper way to initialize this int array when passed as a type argument?
I've tried: int[]
, array<int,4>
but they all give the error:
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
Upvotes: 0
Views: 90
Reputation: 3186
You can initialize the array with one set of angle brackets.
int main()
{
std::unordered_map<char,std::array<int,4>> inv = {{ 'a', {1,2,3,4} }};
for (auto &&i : inv)
std::cout<< i.first << "->" <<i.second[0] <<std::endl;
}
Example: https://rextester.com/FOVMLC70132
Upvotes: 2
Reputation: 38267
This should work:
#include <array>
std::unordered_map<char, std::array<int, 4>> inv = {{ 'a', {{0, 0, 1, 0}} }};
Upvotes: 5