在c++中定义map类型的map
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;
相关文章:
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 如何使用 uint64_t 键类型从 std::map<int, std::string> 返回值?
- 类型为 'std::map< char,int > 的 <Swig 对象的代理
- std::map 保存任何值类型
- 标准::map键类型的严格弱排序概念
- 如何在 Visual C++ 中从返回类型为 map 的函数返回 null?
- 在变量名后声明带有 () 的非内部类型与不使用变量名的行为不同。即 std::map<int,char>x(); - 这是怎么回事?
- 将参数列表未知的可变参数模板类型定义为 std::map 值类型
- 不完整的类型为 std::map 的成员
- 当 map 是一个整数数组并且由 operator[] 创建时,它是否初始化其映射类型
- 具有 std::map 和 std::variant 的不完整类型
- 如何在 c++ 中使用返回类型导出函数 std::map
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 为什么C++允许类型没有 std::map 的默认构造函数,而没有 std::p air
- 将QML数组和MAP/对象类型与C 区分开
- std::map使用不同的数据类型进行值
- 为什么缩小转换范围不能防止错误类型的map.insert()失败
- Qt nmake:错误 C3203:"map":非专用类模板不能用作模板参数"base"的模板参数,预期为真实类型
- 如何更新map
>类型的映射 - 在c++中定义map类型的map