首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> VC >> 關於VC++

Visual C++ 最常見 20 種編譯/連結錯誤代碼速查表

     編輯:關於VC++

整理 Visual C++ 開發中高頻出現的 20 個錯誤/警告代碼,附帶中文說明與常見成因,助您快速定位並修正問題。

代碼訊息中文說明與常見原因
C1010unexpected end of file while looking for precompiled header directive尋找預編譯標頭時遇到檔案結尾。通常是忘記 #include "stdafx.h" 或專案設定不一致。
C1083Cannot open include file: 'xxx.h': No such file or directory找不到包含檔。檢查專案「Additional Include Directories」或檔案是否存在。
C2011'xxx' : 'class' type redefinition類型重複定義。常因標頭檔未加防重複巨集(#pragma once 或 #ifndef)且被多次包含。
C2018unknown character '0xa3'無法識別的字元(全形中文標點或漢字混入程式碼)。改用半形字元或移除中文註解。
C2057expected constant expression需要常數運算式。switch 的 case 標籤必須為編譯期常數。
C2065'IDD_MYDIALOG' : undeclared identifier未宣告的識別碼。資源符號未定義或拼寫錯誤,檢查 resource.h。
C2082redefinition of formal parameter 'xxx'函式參數在函式主體中被重複定義(如區域變數同名)。
C2143syntax error : missing ';' before '{'語法錯誤:{ 前缺少分號。常見於類別定義結尾遺漏 ;。
C2146syntax error : missing ';' before identifier 'xxx'語法錯誤:識別碼前缺少分號。通常是前一行陳述句未結尾。
C2196case value 'xxx' already usedswitch 中 case 值重複。
C2509'OnTimer' : member function not declared in 'CHelloView'成員函數未在類別中宣告。ClassWizard 加入訊息對應時應自動宣告,手動修改易遺漏。
C2511'reset' : overloaded member function not found in 'B'重載函數簽章與類別宣告不符。檢查參數型別、const 屬性、呼叫約定。
C2555'B::f1' : overriding virtual function differs from 'A::f1' only by return type覆寫虛函數僅回傳型別不同(或呼叫約定不同),C++ 不允許。
C2660'SetTimer' : function does not take 2 parameters函數參數個數不符。查閱 MSDN 確認正確參數列表。
C4035'func' : no return value非 void 函數缺少 return 陳述句,或所有路徑未回傳值。
C4553'==' : operator has no effect; did you intend '='?== 無副作用,疑為誤寫成 =。常見於 if (a == b) 應為 if (a = b)。
C4700local variable 'xxx' used without having been initialized區域變數未初始化即使用。宣告時賦初值或確保所有路徑先賦值。
C4716'CMyApp::InitInstance' : must return a value非 void 函數必須回傳值。MFC 應用程式類別 InitInstance 需回傳 TRUE/FALSE。
LNK1168cannot open Debug/xxx.exe for writing無法寫入輸出檔。通常是程式仍在執行(未關閉),或防毒軟體鎖定。
LNK2001unresolved external symbol "public: virtual __thiscall Cxxx::~Cxxx(void)"連結時找不到外部符號(函數/變數未實作、靜態成員未定義、庫檔未連結)。

其他常見訊息

  • function call missing argument list:呼叫函數未提供參數列表(如忘記 ())。
  • member function definition looks like a ctor, but name does not match enclosing class:建構函數名稱與類別名稱不符。
  • unexpected end of file while looking for precompiled header directive:編譯非正常終止導致預編譯標頭搜尋失敗。

善用「輸出」視窗雙擊錯誤行直接跳轉,配合 MSDN 搜尋錯誤代碼,可大幅縮短除錯時間。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved