【发布时间】:2021-09-22 20:50:19
【问题描述】:
我正在动态加载一个包含很多方法的 DLL,并且我有一个处理多个 DLL 方法的 typedef:
typedef int32_t (__cdecl *MYPROC)(const char *url, const char *options, const char *body, int32_t length); // GET, POST, HTTP test
每当我创建另一个 typedef 来处理单独的函数时:
typedef int32_t (__cdecl *MYPROC)(const char *json_blob, const char *response, int32_t length); // ParseVal
我遇到了关于声明冲突的错误:
conflicting declaration 'typedef int32_t (__attribute__((cdecl)) * MYPROC)(const char*, const char*, int32_t)'
typedef int32_t (__cdecl *MYPROC)(const char *json_blob, const char *response, int32_t length); // ParseVal
^
note: previous declaration as 'typedef int32_t (__attribute__((cdecl)) * MYPROC)(const char*, const char*, const char*, int32_t)'
typedef int32_t (__cdecl *MYPROC)(const char *url, const char *options, const char *body, int32_t length); // GET, POST, HTTP test
我不确定这是否是处理 DLL 方法的正确方法,因此我愿意接受建议。我是 C++ 的这个特性的新手,并且很长一段时间没有使用过这种语言,如果这很明显,请道歉。
【问题讨论】:
-
你为什么将两个类型别名都命名为
MYPROC?这与尝试typedef int T; typedef float T;相同 - 显然 typeT不能声明为引用两种不同的类型。 -
啊。我现在明白了。我将其视为 MYPROC 是系统定义的类型而不是名称..这将破坏使用 typedef 的全部目的。谢谢你的澄清。