在函数定义中指定参数默认值会导致错误 C2143:语法错误:'='之前缺少')'

specifying argument default value in function definition causes error C2143: syntax error : missing ')' before '='

本文关键字:错误 函数 定义 语法 默认值 参数 C2143      更新时间:2023-10-16

我有以下声明:

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

其中最后一个agrument具有默认值CCD_ 1。

当我编译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