C++:我使用什么类型来定义此地图
C++: What type do I use for the definition of this map?
所以,我有一个函数指针定义为:
unsigned static int (*current_hash_function)(unsigned int);
我正在尝试制作指向函数名称的指针映射:
typedef std::map<fptr_t, std::string> function_map_t;
但是我收到此错误:
src/main.h:24:错误:ISO C++禁止声明无类型的
‘fptr_t’
其他代码:
主.h:
typedef (*fptr_t)(unsigned int*);
typedef std::map<fptr_t, std::string> function_map_t;
function_map_t fmap;
你的"main.h"代码没有为函数指针类型定义提供返回类型。这对我有用:
#include <map>
#include <string>
int main()
{
typedef unsigned (*fptr_t)(unsigned);
typedef std::map<fptr_t, std::string> function_map_t;
function_map_t fmap;
}
您错过了返回类型:
typedef int (*fptr_t)(unsigned int*);
函数指针的类型定义是:
typedef unsigned int (*fptr_t)(unsigned int)
。然后,您可以像这样声明您的地图:
typedef std::map<fptr_t, std::string> function_map_t;
你记得对函数指针进行 typedef 吗?
typedef unsigned int (*fptr_t)(unsigned int);
我相信这是正确的语法
函数
指针的typedef
缺少返回类型:
typedef unsigned int (*fptr_t)(unsigned int *);
以上是指向返回 unsigned int
并将unsigned int *
作为参数的函数的指针的typedef
。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 部分定义/别名模板模板参数
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 为什么不;名字在地图上是按顺序排列的吗
- #为""定义宏;静态";针对不同的上下文
- 在地图中使用自定义删除器存储unique_ptr
- C 中STL地图的自定义分配器
- 您可以将STD :: MAP变成带有自定义比较器的无序地图吗?
- 使用大理石的自定义地图叠加
- 带钥匙的C 11地图定义了一个值范围
- 如何以自定义类/比较器作为密钥创建地图
- 从无序地图创建以自定义类作为键的地图.但是,由于const而无法使用的要素
- 将自定义类型作为地图的可能键的可能方法有哪些
- STL地图 - 何时使用自定义比较器
- 使用自定义对象的地图使用MAP?可能是语法问题
- 地图地图和自定义分配器
- 正在尝试打印未定义的地图
- C++:我使用什么类型来定义此地图