[英]Can you help resolve this error? (g++ prototype does not match any in class)
這是編譯器的輸出:
[brian@brian-arch-laptop Lab1]$ g++ -g -Wall -std=c++11 objectIO.cpp main.cpp -o main
objectIO.cpp:33:14: error: prototype for ‘std::vector<Type> objectIO<Type>::loadObjects(Type, std::string, unsigned int, unsigned int)’ does not match any in class ‘objectIO<Type>’
vector<Type> objectIO<Type>::loadObjects(Type dummyObject,
^
objectIO.h:14:23: error: candidate is: static std::vector<Type> objectIO<Type>::loadObjects(std::string, unsigned int, unsigned int)
static vector<Type> loadObjects(Type dummyObject, string fileName, unsigned numObjects,unsigned numLinesPerObject);
^
從我的研究中,我發現該錯誤通常在聲明一個函數時發生,但是在定義函數時,它具有不同數量的參數或不同類型的參數。 我還發現,當使用“ const”聲明函數但在定義函數時未使用“ const”時,通常會發生此錯誤。
這些情況都不符合我的情況。 我有匹配的項,並且我沒有使函數保持不變。 這是我來源中有疑問的行:
從我的源(.cpp)文件:
template <class Type>
vector<Type> objectIO<Type>::loadObjects(Type dummyObject,
string filename,
unsigned numObjects,
unsigned numLinesPerObject){/*functionality here*/}
從我的標頭(.h)文件中:
template <class Type>
class objectIO{
public:
static vector<Type> loadObjects(Type dummyObject, string fileName,
unsigned numObjects,
unsigned numLinesPerObject);
}
模板類的所有定義都應放在一個頭文件中。
在班級結束大括號后,您的代碼缺少分號:
template <class Type>
class objectIO{
public:
static vector<Type> loadObjects(Type dummyObject, string fileName,
unsigned numObjects,
unsigned numLinesPerObject);
} /* <-- RIGHT HERE */
通常這會弄亂源代碼中接下來的內容,有時還會顯示錯誤消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.