簡體   English   中英

在函數定義中指定參數默認值會導致錯誤C2143:語法錯誤:在'='之前缺少')'

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

我有以下聲明:

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

最后一個agrument的默認值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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM