简体   繁体   English

在C ++中定义地图类型的地图?

[英]Define a map of map type in C++?

I am trying to define a unordered map from long to a map from long to FILE * , but keep getting compiler error. 我试图从定义一个无序地图longmap ,从longFILE * ,但不断收到编译器错误。 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

It's the placing of the asterisk: 这是星号的位置:

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

will do it. 会做的。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM