[英]Define a map of map type in C++?
我試圖從定義一個無序地圖long
到map
,從long
到FILE *
,但不斷收到編譯器錯誤。 知道如何糾正嗎?
#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;
}
這是編譯器錯誤
$ 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
這是星號的位置:
typedef std::unordered_map<long, std::unordered_map<long, FILE*>> TYPE1;
會做的。
請注意星號:
typedef std::unordered_map<long, std::unordered_map<long, *FILE>> TYPE1;
更改為:
typedef std::unordered_map<long, std::unordered_map<long, FILE*>> TYPE1;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.