【问题标题】:specifying argument default value in function definition causes error C2143: syntax error : missing ')' before '='在函数定义中指定参数默认值会导致错误 C2143:语法错误:在 '=' 之前缺少 ')'
【发布时间】:2014-12-21 00:21:25
【问题描述】:

我有以下声明:

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: syntax error : missing ')' before '=' 并且宏 DLL 如下:

#define DLL __declspec(dllimport)

【问题讨论】:

    标签: c++ c dll extern-c


    【解决方案1】:

    C 中没有默认参数。

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

    例如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多