Reputation: 5069
I am trying to define a unordered map from long
to a map
from long
to FILE *
, but keep getting compiler error. Any idea how to correct it?
#include <string>
#include <iostream>
#include <stdio.h>
#include<unordered_map>
using namespace std;
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short uint16;
typedef unsigned char uchar;
typedef std::unordered_map<long, std::unordered_map<long, *FILE> > TYPE1;
int main(int argc, char *argv[]) {
TYPE1 x;
x[1][2] = fopen(argv[1], "rb");
return 0;
}
Here is the compiler error
$ g++ -std=c++11 te2a.cc
te2a.cc:15:64: error: template argument 2 is invalid
te2a.cc:15:64: error: template argument 5 is invalid
te2a.cc:15:66: error: template argument 2 is invalid
te2a.cc:15:66: error: template argument 5 is invalid
te2a.cc:15:73: error: invalid type in declaration before ‘;’ token
te2a.cc: In function ‘int main(int, char**)’:
te2a.cc:19:5: error: invalid types ‘TYPE1 {aka int}[int]’ for array subscript
Upvotes: 0
Views: 103
Reputation: 4118
Note the asterisk:
typedef std::unordered_map<long, std::unordered_map<long, *FILE>> TYPE1;
change it to:
typedef std::unordered_map<long, std::unordered_map<long, FILE*>> TYPE1;
Upvotes: 1
Reputation: 638
It's the placing of the asterisk:
typedef std::unordered_map<long, std::unordered_map<long, FILE*>> TYPE1;
will do it.
Upvotes: 4