gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:58:37 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com