gpt4 book ai didi

c++ - 在函数定义中指定参数默认值导致错误 C2143 : syntax error : missing ')' before '='

转载 作者:太空宇宙 更新时间:2023-11-04 02:01:42 25 4
gpt4 key购买 nike

我有以下声明:

DLL EntityHandle scenemanager_create_entity
(SceneManagerHandle handle,
const char* name,
const char* mesh_name,
const char* group_name = 0);

其中最后一个参数具有默认值 group_name = 0

当我编译 C++ DLL (/TP) 时,它工作正常,而编译宏 DLL 时如下:

#define DLL extern "C" __declspec(dllexport)

但是,当我尝试编译与此 DLL 链接的 C 应用程序 (/TC) 时,出现错误 C2143:语法错误:在“=”之前缺少“)”,宏 DLL 如下:

#define DLL __declspec(dllimport)

最佳答案

C 中没有默认参数。

您可以使用宏 __cplusplus 来检查代码是由 C++ 编译器还是 C 编译器编译的。

例如

#ifdef __cplusplus
// C++ function declaration...
#else
// C function declaration...
#endif

关于c++ - 在函数定义中指定参数默认值导致错误 C2143 : syntax error : missing ')' before '=' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26560172/

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