0

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 
0

2 Answers 2

4

It's the placing of the asterisk:

typedef std::unordered_map<long, std::unordered_map<long, FILE*>> TYPE1;

will do it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @r2-dequeue, that's it! Will accept your answer in a few minutes when SO allows.
@codingFun In addition to this, you want to change x[1][2] to x[0][1] I think.
1

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; 

1 Comment

Thanks @tryinhard. Your answer is right. Wish I can accept it too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.