error: '[class name]' does not name a type
這個問題困擾了我好幾個小時,真的很痛苦,所以記錄一下。
我編譯平臺是Linux,編譯命令如下:
g++ -g -Wall -std=c++11 -I/usr/local/mysql/include -I/usr/local/curl/include -o obj/tc_mysql.o -c tc_mysql.cpp
從命令中可以看出,我是對原始檔tc_mysql.cpp進行編譯。但是卻始終報如下錯誤:
tc_mysql.cpp:12:1: error: 'TC_Mysql' does not name a type
TC_Mysql::TC_Mysql()
我發誓,我在原始檔中一定包含了標頭檔案,也不會像網上所說的存在多個標頭檔案的相互依賴,標頭檔案和原始檔如下:
//標頭檔案tc_mysql.h
#ifndef __TC_MYSQL_H
#define __TC_MYSQL_H
#include <mysql.h>
namespace mysqlHelper
{
class TC_Mysql
{
public:
/**
* @brief 建構函式
*/
TC_Mysql();
protected:
/**
* @brief copy contructor,只申明,不定義,保證不被使用
*/
TC_Mysql(const TC_Mysql &tcMysql);
/**
* @brief 只申明,不定義,保證不被使用
*/
TC_Mysql &operator=(const TC_Mysql &tcMysql);
private:
/**
* 資料庫指標
*/
MYSQL *_pstMql;
};
}
#endif
//原始檔tc_mysql.cpp
#include "tc_mysql.h"
namespace taf
{
TC_Mysql::TC_Mysql():_bConnected(false){
_pstMql = mysql_init(NULL);
}
}
聰明的你也許發現了問題的原因,但是我當時卻困惑了很久,百度和google許久都沒有解決問題,最後才發現端倪,真的是被自己坑了,原來使用名稱空間的時候標頭檔案和原始檔的名稱空間不一致所導致的問題。
寫程式碼,真的要細心,切勿粗心啊!!!
相關文章
- error :does not name a typeError
- error: 'cout' does not name a type|Error
- error: ‘xxx’ does not name a typeError
- error: ‘變數名‘ does not name a type|Error變數
- ‘map’ does not name a type
- vector does not name a type
- ndk編譯錯誤:error: 'override' does not name a type編譯ErrorIDE
- does not name a type 的可能性
- 'int32_t' does not name a type
- Qt 報錯 “類名”does not name a typeQT
- QT中error: xxx does not name a type xxx錯誤QTError
- `QtValidLicenseForCoreModule' does not name a type 錯誤的解決QTREM
- 編譯錯誤 --- does not name a type和field `XX' has incomplete type編譯
- 編譯錯誤--------:XX does not name a type和field `XX' has incomplete type編譯
- Qt 標頭檔案互相包含會報錯'' does not name a typeQT
- C++ doesn't name a typeC++
- Android之NDK開發錯誤 error: unknown type name 'JNIEXPORT'AndroidErrorExport
- A resource type with the name 'ora.daemon.type' is already registered
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- HTML中的tag、element、class、name、idHTML
- 兩個C++編譯錯誤及解決辦法--does not name a type和field `XX' has incomplete typeC++編譯
- Caused by: Error: ' ' is not a valid resource name characterError
- Error creating bean with name ‘dataSource‘ErrorBean
- emulator: ERROR: unknown virtual device nameErrordev
- grep: PCRE does not support L, l, N{name}, U, or u
- DB_NAME&TANCE_NAME&DB_UNIQUE_NAME&ORACLE_SID&GLOBAL_NAME&DB_DOMAIN&SERVICE_NAMEOracleAI
- PSQLexception: ERROR : type "signed" does not existSQLExceptionError
- Error creating bean with name 解決ErrorBean
- element-ui中row-class-name的用法UI
- CUUG 筆記ORACLE db_name instance_name gobal_name service_name db_unique_name分析筆記OracleGo
- Import Error: cannot import name ‘export_saved_modelImportErrorExport
- 更改Global_name, domain_name, db_name 的方法AI
- DB_NAME、DB_UNIQUE_NAME、SERVICE_NAME和INSTANCE_NAME等的區別
- Selenium4自動化測試2--元素定位By.ID,By.CLASS_NAME,By.TAG_NAME
- ERROR: failed to establish dependency between database db_name and diskgroupErrorAIDatabase
- WPF筆記3——x:Name 與 Name筆記
- db_name,db_domain, global_name, service_name的區別AI
- Oracle修改instance_name、db_name、db_unique_name、service_namesOracle