編譯錯誤--------:XX does not name a type和field `XX' has incomplete type
</pre><pre name="code" class="html"><p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">兩個C++編譯錯誤及解決辦法--does not name a type和field `XX' has incomplete type</p><p style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"> </p><table border="0" style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"><tbody><tr><td><p>
</p><p>編譯錯誤一:XX does not name a type</p><p>編譯錯誤二:field `XX' has incomplete type</p><p>編譯錯誤一:XX does not name a type</p><p>例子如下(在別處看到的):</p><p>class B{</p><p>public:</p><p>B(){}</p><p>~B(){}</p><p>private:</p><p>A a;</p><p>};</p><p>class A{</p><p>public:</p><p>A(){}</p><p>~A(){}</p><p>private:</p><p>int a;</p><p>};</p><p>編譯成則將報一個error:"A does not name a type"</p><p>報錯的位置為紅色那一行。</p><p>即使clase A和class B分別在兩個檔案定義,並且在定義B的檔案頭中#include了class A的標頭檔案也同樣會報這個錯(這是因為編譯和連結之間的先後關係造成的)。</p><p>解決該錯誤的辦法:</p><p>在class B定義宣告之前先宣告一下class A, 如下:</p><p>class A;</p><p>class B{</p><p>public:</p><p>B(){}</p><p>~B(){}</p><p>private:</p><p>A a;</p><p>};</p><p>class A{</p><p>public:</p><p>A(){}</p><p>~A(){}</p><p>private:</p><p>int a;</p><p>};</p><p>編譯錯誤二:field `XX' has incomplete type</p><p>同樣緊跟上面的例子,通過問題一的辦法,第一個錯誤已經消失,但是馬上第二個錯誤就出現了!還是同一個位置。</p><p>這個錯誤的意思,就是說class B中的XX域的型別不夠完整,為什麼呢?明明class A後面已經定義好了啊。其實原因還是和前面一樣,在class B定義之前,我們也只是對class A進行了宣告而並沒有進行具體的定義,所以解決該錯誤的方法是:</p><p>將class B定義中的A域改用指標就行了。改正後程式碼為:</p><p>class A;</p><p>class B{</p><p>public:</p><p>B(){}</p><p>~B(){}</p><p>private:</p><p>A *a;</p><p>};</p><p>class A{</p><p>public:</p><p>A(){}</p><p>~A(){}</p><p>private:</p><p>int a;</p><p>};</p><p>這樣,這段簡單的程式碼才能沒有錯誤的通過編譯。</p></td></tr></tbody></table>
相關文章
- 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
- Go 自定義日期時間格式解析解決方案 - 解決 `parsing time xx as xx: cannot parse xx as xx` 錯誤Go
- Elasticsearch報Call to undefined xx makeAllSearchable()錯誤ElasticsearchUndefined
- std::unique_ptr使用incomplete type的報錯分析和解決
- PSQLexception: ERROR : type "signed" does not existSQLExceptionError
- Angular 錯誤訊息:ERROR Error NullInjectorError No provider for XXAngularErrorNullIDE
- 通俗易懂解釋一類和二類錯誤(Type I Error Type II Error)Error
- PostgreSQL cache lookup failed for type XXXX 錯誤SQLAI
- windows下使用mingw和msvc靜態編譯Qt5.15.xxWindows編譯QT
- Oracle案例08——xx.xx.xx.xx,表空間 SYSAUX 使用率>95%%OracleUX
- 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
- HTTP的response code 1xx,2xx,3xx,4xx,5xx分別代表什麼HTTP
- 使用jadx反編譯 除錯“XX值得買”APP獲取介面簽名key(一)編譯除錯APP
- MySQL錯誤修復:Table xx is marked as crashed and last (automatic?) repair failedMySqlASTAI
- Angular 依賴注入錯誤訊息:ERROR Error NullInjectorError No provider for XXAngular依賴注入ErrorNullIDE
- 如何處理ABAP DDIC_TYPE_INCONSISTENCY錯誤
- MYSQL中 TYPE=MyISAM 錯誤的解決方法MySql
- navicat無法連線遠端的mysql--Host ‘xx.xx.xx.xx‘ is not allowed to connect to this MySQL server“MySqlServer
- SharePlex reader missed marker wait for xx but got xxAIGo
- 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
- [sth]xx
- appscan 遇到 xx.xx.xx.xx/8080/web/#/url,是不是就不能識別延伸的網址啦。。APPWeb
- JAVA -Xms -Xmx -XX:PermSize -XX:MaxPermSize 區別Java
- 簡介響應狀態碼1xx、2xx、5xx
- iOS-新手常見錯誤:this class is not key value coding-compliant for the key xxiOS
- c# Api 錯誤 Unable to resolve service for type while attempting to activate C#APIWhile