簡體   English   中英

在C ++中定義地圖類型的地圖?

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

我試圖從定義一個無序地圖longmap ,從longFILE * ,但不斷收到編譯器錯誤。 知道如何糾正嗎?

#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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM