C++:我使用什么类型来定义这个映射?

标签 c++ dictionary function-pointers

所以,我有一个函数指针定义为:

unsigned static int (*current_hash_function)(unsigned int);

我正在尝试制作指向函数名称的指针映射:

typedef std::map<fptr_t, std::string> function_map_t;

但是我得到这个错误:

src/main.h:24: error: ISO C++ forbids declaration of ‘fptr_t’ with no type

其他代码:

ma​​in.h:

typedef (*fptr_t)(unsigned int*);
typedef std::map<fptr_t, std::string> function_map_t;
function_map_t fmap;

最佳答案

您的“main.h”代码没有为函数指针 typedef 提供返回类型。这对我有用:

#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;
}

关于C++:我使用什么类型来定义这个映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5955325/

相关文章:

c++ - QLabel 在 Qt 中获取 QImage 时如何设置 QSpinBox?

c++ - 谁能推荐一个好的 C/C++ RESTful 框架

c# - 如何将 EF 查询与字典连接起来

python - python 新手从文件创建两个字典需要特定行

c++,指向函数 vector 的指针的STL映射

c++ - 将任何 lambda 函数(包括捕获 lambda)转换为 std::function 对象的模板

c++ - 调用具有不同 arg 计数的函数

c++ - 使用 ffmpeg 将缓冲区中的 H.264 流写入可流式传输的 mp4

c++ - 如何知道SDL2中按下了哪些键

map 抛出错误中的c++自定义对象