C++錯誤綜合介紹.ppt_第1頁
C++錯誤綜合介紹.ppt_第2頁
C++錯誤綜合介紹.ppt_第3頁
C++錯誤綜合介紹.ppt_第4頁
C++錯誤綜合介紹.ppt_第5頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、C+錯誤綜合介紹,掌握自己找錯改錯的方法,class CForm private: char title40; int width; int height; public: CForm() strcpy(title,Form1); widht = 400; height = 350; ,1.使用未經(jīng)定義過的標識符的錯誤,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp e:課件c+09c+錯誤綜合練習(xí)form.h(11) : error C2065: strcpy : undeclared identifier e:課件c+09

2、c+錯誤綜合練習(xí)form.h(12) : error C2065: widht : undeclared identifier 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),Compiling 編譯 Error 錯誤 Warning 警告 Underclared 沒有定義/聲明 Identifier 標識符,錯誤認識,這是一個在編譯期間發(fā)現(xiàn)的語法性錯誤,錯誤報告了中出現(xiàn)了兩個錯誤點,它們的內(nèi)容都是: undeclared identifier “沒有定義過的標識符”,錯誤認識,這是一個在編譯期間發(fā)現(xiàn)的語法性錯誤,錯誤報告了中出現(xiàn)了兩個

3、錯誤點,它們的內(nèi)容都是: undeclared identifier “沒有定義過的標識符”,改錯提示,在程序中找到錯誤的位置和錯誤的標識符,看該標識符有沒有被定義過。如果有,則一般是因為同學(xué)標識符的使用名與定義時的名稱不一致,要特別注意大小寫,#include #include class CForm private: char title40; int width; int height; public: CForm() strcpy(title,Form1) width = 400; height = 350; ,2.語句沒有使用; 結(jié)束的錯誤,-Configuration: 錯誤綜合練

4、習(xí) - Win32 Debug- Compiling. Demo.cpp e:課件c+09c+錯誤綜合練習(xí)form.h(14) : error C2146: syntax error : missing ; before identifier width 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),syntax 句法 missing 缺少,丟失,錯誤認識,錯誤認識,這是一個在編譯期間發(fā)現(xiàn)的語句錯誤,錯誤報告了中出現(xiàn)了1個錯誤點,它們的內(nèi)容是: syntax error : missing ; before identifier wi

5、dth “在標識符widht前面缺少;”,改錯提示,在程序中找到錯誤的位置,一般錯誤并不是在這個位置所在的行,而是在該行前面一行的末尾處缺少;,#include #include class CForm private: char title40; int width; int height; public: CForm() strcpy(title,”Form1”); width = 400; height = 350; ,3.非法(無法理解的)字符錯誤,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp e:課件c+09c+錯

6、誤綜合練習(xí)form.h(13) : error C2018: unknown character 0 xa1 e:課件c+09c+錯誤綜合練習(xí)form.h(13) : error C2018: unknown character 0 xb1 e:課件c+09c+錯誤綜合練習(xí)form.h(13) : error C2018: unknown character 0 xa3 e:課件c+09c+錯誤綜合練習(xí)form.h(13) : error C2018: unknown character 0 xbb 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warni

7、ng(s),unknown 無法知道的、看不懂的 character 字符,錯誤認識,錯誤認識,這是一個在編譯期間發(fā)現(xiàn)的錯誤,錯誤內(nèi)容是: error C2018: unknown character 0 xa1 “無法理解的字符0 xa1” 錯誤提示在程序當前位置有非法的字符,比如:中文字符對于程序來說就屬于非法字符,改錯提示,在程序中找到錯誤的位置,把中文的字符改為英文字符,特別要主要中文的“”和;的誤寫或缺失。,#include #include class CForm private: char title40; int width; int height; public: CForm

8、() strcpy(title,Form1); width = 400; height = 350;,4.沒有結(jié)束塊的語法錯誤,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(7) : fatal error C1004: unexpected end of file found 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),fatal 致命的 unexpected 未終止的 end of file 文件的末尾 Fou

9、nd 發(fā)現(xiàn),錯誤認識,錯誤認識,這是一個在編譯期間發(fā)現(xiàn)的致命錯誤,錯誤內(nèi)容是: fatal error C1004: unexpected end of file found “在文件末尾發(fā)現(xiàn)為終止的意外” 通常是 不成對,特別是沒有結(jié)束 ,改錯提示,這個錯誤的位置很難判斷,需要程序員耐心仔細的一個一個塊對進行查找。因此,如果保持比較良好的程序編寫習(xí)慣是找出這一問題的捷徑。,#include #include Form.h void mian() ,5.沒有main()的鏈接時錯誤,或者根本沒有,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling.

10、Demo.cpp Linking. LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/錯誤綜合練習(xí).exe : fatal error LNK1120: 1 unresolved externals 執(zhí)行 link.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),這個問題的英語翻譯不夠準確,因此,學(xué)員們可以記住這個symbol_main的單詞組合,它只有一種錯誤的可能 Linking 鏈接 symbol_main main符號,錯誤認識,錯誤認識,

11、這是一個在編譯過后的鏈接過程中發(fā)現(xiàn)的錯誤,錯誤內(nèi)容是: unresolved external symbol _main Debug/錯誤綜合練習(xí).exe : fatal error LNK1120: 1 unresolved externals “在鏈接的XXX.exe文件中出現(xiàn)的關(guān)于main符號的未確定的外部錯誤” 通常是main()的單詞寫錯了,或根本沒有,改錯提示,只要看看main有沒有寫對就可以了,注意main是函數(shù),要寫成: main() ,6.擁有超過一個以上main()的錯誤,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. De

12、mo.cpp Linking. Demo2.obj : error LNK2005: _main already defined in Demo.obj Debug/錯誤綜合練習(xí).exe : fatal error LNK1169: one or more multiply defined symbols found 執(zhí)行 link.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),already 已經(jīng) defined 被定義過 multiply 多次,錯誤認識,錯誤認識,這是一個在編譯過后的鏈接過程中發(fā)現(xiàn)的錯誤,錯誤內(nèi)容是: Demo2.obj :

13、 error LNK2005: _main already defined in Demo.obj Debug/ 錯誤綜合練習(xí).exe : fatal error LNK1169: one or more multiply defined “_main已經(jīng)在Demo.obj中被定義過了,鏈接的時候出現(xiàn)了超過一個以上的定義” 通常是一個工程中出現(xiàn)了多個main(),改錯提示,只保留一個main(),#include #include Form.h void main() CForm form1; form1.SetTitle(); form1.SetSize(500); ,7.調(diào)用函數(shù)時出現(xiàn)的錯

14、誤,請對著類中成員函數(shù)定義時的參數(shù)類型和個數(shù),-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(7) : error C2039: SetTile : is not a member of CForm e:課件c+09c+錯誤綜合練習(xí)form.h(4) : see declaration of CForm E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(8) : error C2660: SetSize : function does not take 1 parameters

15、 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),member 成員,一般指成員屬性或成員函數(shù) declaration 定義,一般指類或函數(shù)的結(jié)構(gòu)定義 function 函數(shù) parameters 參數(shù),錯誤認識,錯誤認識,E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(7) : error C2039: SetTile : is not a member of CForm e:課件c+09c+錯誤綜合練習(xí)form.h(4) : see declaration of CForm E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(8)

16、: error C2660: SetSize : function does not take 1 parameters SetTile不是一個CForm類的成員,請查看一下CForm類的定義。 SetSize函數(shù)不能夠只給出一個參數(shù),改錯提示,嚴格按照函數(shù)定義來進行調(diào)用,一定保證正確的函數(shù)名和正確的參數(shù)的類型、個數(shù)和參數(shù)的順序。,#include #include Form.h void main() CForm form1; form1.SetTitle(My Form); form1.SetSize(500,350); form1.width = 400; ,8.不能訪問成員時的錯誤,訪

17、問了類的私有成員,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(9) : error C2248: width : cannot access private member declared in class CForm e:課件c+09c+錯誤綜合練習(xí)form.h(7) : see declaration of width 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),access 訪問,使用,錯誤認識,錯誤認識,

18、error C2248: width : cannot access private member declared in class CForm e:課件c+09c+錯誤綜合練習(xí)form.h(7) : see declaration of width 不能訪問在CForm類定義的私有成員width。 請看關(guān)于width的定義,改錯提示,如果你不想在類中把這個成員定義為public類型的話,那么就定義個public類型的成員方法來訪問這width吧,#include #include Form.h void main() CForm form1; form1.SetTitle(My Form)

19、; form1.SetSize(500,350); CForm form1; ,9.不能訪問成員時的錯誤,Form1這個標識符被重復(fù)定義了。類似的還有 for(int i=0;i10;i+) for(int i=0;i5;i+) ,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(10) : error C2086: form1 : redefinition 執(zhí)行 cl.exe 時出錯. 錯誤綜合練習(xí).exe - 1 error(s), 0 warning(s),redefini

20、tion 重復(fù)定義,錯誤認識,錯誤認識,error C2086: form1 : redefinition form1被重復(fù)定義了,改錯提示,把除第一個以外的form1換個名字即可。,警告,警告是不影響程序運行的一種提醒。 以下我們介紹兩種無關(guān)緊要的警告。,#include #include Form.h void main() int a,b,c; float f1,f2; f1 = 20.5; f2 = 38.6; ,10.沒有使用過的變量和為float類型變量賦予double類型的值,末尾沒有f的小數(shù)常量都是屬于double類型的,-Configuration: 錯誤綜合練習(xí) - Win32 Debug- Compiling. Demo.cpp E:課件c+09c+錯誤綜合練習(xí)Demo.cpp(11) : warning C4305: = : truncation from const d

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論