編譯錯誤 --- does not name a type和field `XX' has incomplete type
兩個C++編譯錯誤及解決辦法--does not name a type和field `XX' has incomplete type
編譯錯誤一:XX does not name a type 編譯錯誤二:field `XX' has incomplete type 編譯錯誤一:XX does not name a type, 中文意思為“XX沒有命名一個型別“ 拿個例子來講,如果兩個類定義如下: class B{ public: B(){} ~B(){} private: A a; }; class A{ public: A(){} ~A(){} private: int a; }; 編譯成則將報一個error:"A does not name a type" 報錯的位置為紅色那一行。 即使clase A和class B分別在兩個檔案定義,並且在定義B的檔案頭中#include了class A的標頭檔案也同樣會報這個錯(這是因為編譯和連結之間的先後關係造成的)。 解決該錯誤的辦法: 在class B定義宣告之前先宣告一下class A, 如下: class A; class B{ public: B(){} ~B(){} private: A a; }; class A{ public: A(){} ~A(){} private: int a; }; 編譯錯誤二:field `XX' has incomplete type 同樣緊跟上面的例子,通過問題一的辦法,第一個錯誤已經消失,但是馬上第二個錯誤就出現了!還是同一個位置。 這個錯誤的意思,就是說class B中的XX域的型別不夠完整,為什麼呢?明明class A後面已經定義好了啊。其實原因還是和前面一樣,在class B定義之前,我們也只是對class A進行了宣告而並沒有進行具體的定義,所以解決該錯誤的方法是: 將class B定義中的A域改用指標就行了。改正後程式碼為: class A; class B{ public: B(){} ~B(){} private: A *a; }; class A{ public: A(){} ~A(){} private: int a; }; 這樣,這段簡單的程式碼才能沒有錯誤的通過編譯。 |
相關文章
- QT中error: xxx does not name a type xxx錯誤QTError
- ‘map’ does not name a type
- Qt 報錯 “類名”does not name a typeQT
- error: 'cout' does not name a type|Error
- error: ‘xxx’ does not name a typeError
- does not name a type 的可能性
- error: ‘變數名‘ does not name a type|Error變數
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- xcode6編譯錯誤,提示Expected a typeXCode編譯
- dcat-admin 表單 Field type [autocomplete] does not exist.
- Android之NDK開發錯誤 error: unknown type name 'JNIEXPORT'AndroidErrorExport
- std::unique_ptr使用incomplete type的報錯分析和解決
- PSQLexception: ERROR : type "signed" does not existSQLExceptionError
- 通俗易懂解釋一類和二類錯誤(Type I Error Type II Error)Error
- PostgreSQL cache lookup failed for type XXXX 錯誤SQLAI
- Property 'context' does not exist on type 'NodeRequire'.ts(2339)ContextUI
- editor does not contain a main type Maven專案AIMaven
- Rasa init報錯:AttributeError: type object 'Callable' has no attribute '_abc_registry'ErrorObject
- 如何處理ABAP DDIC_TYPE_INCONSISTENCY錯誤
- MYSQL中 TYPE=MyISAM 錯誤的解決方法MySql
- eclipse中:The type java.lang.object cannot be resolved錯誤(jdk配置錯誤)EclipseJavaObjectJDK
- SAP MRKO Error - For document type RE, an entry is required in field Reference -ErrorUI
- c# Api 錯誤 Unable to resolve service for type while attempting to activate C#APIWhile
- ipvs編譯錯誤編譯
- cannot convert (type interface {}) to type int: need type assertion
- ORA-30012 undo tablespace 'UNDOTBS3' does not exist or of wrong typeS3
- Spring Boot建立DataSource時遇到的錯誤:No supported DataSource type foundSpring Boot
- Go 中 type var string 和 type var = string 的區別Go
- QTCreator 除錯:unknown debugger type “No engine“QT除錯
- querydsl報錯: Attempt to recreate a file for type
- React報錯之Element type is invalidReact
- Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight responHeader
- HITSC_4_Data Type and Type Checking
- ABAP 資料結構啟用時的錯誤訊息 - combination reference table field does not exist資料結構
- opencv 編譯常見錯誤OpenCV編譯
- PHP編譯configure時常見錯誤,和PHP7.1.4 編譯安裝PHP編譯
- Vuex中使用報錯unknown mutation typeVue
- npm報錯 TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string.Received undefineNPMError
- [譯] Story 中 Type Mode 在 iOS 和 Android 上的實現iOSAndroid