我使用Visual Studio 2008 Express版本編譯的頭文件下面的代碼:爲什麼函數聲明返回bool不在我的C++項目中編譯?
bool is_active(widget *w);
widget
較早的定義,
typedef void widget;
的編譯器錯誤抱怨:
>c:\projects\engine\engine\engine.h(451) : error C2061: syntax error : identifier 'is_active'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : ';'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : 'type'
對於返回bool
的所有其他函數,我得到類似的錯誤。
注意:下面編譯好了:
void widget_activate_msg(widget *g, message *msg);
爲什麼會出現編譯器錯誤?
有些人要求我張貼代碼 - 這就是:
Line 449: widget * widget_new_from_resource(int resource_id);
Line 450: void widget_delete_one(widget *w);
Line 451: bool is_active(widget *w);
編輯 - 這是現在固定:
@BatchyX評論下面我是否是用C或C++。我不知道的是Visual C++ 2008將編譯任何文件默認(但你可以覆蓋此設置),擴展名爲.c,C爲.cpp。 (編譯包含「Engine.h」的.c文件時導致錯誤)。
你已經完成了'#include「stdafx.h」'在文件的開頭嗎?如果沒有,那麼你應該添加它,因爲它是一個Win32應用程序。 – Naveen 2010-09-13 09:52:34
請顯示'engine.h'的441-451行。 – kennytm 2010-09-13 09:52:51