0
我有一個頭文件,其中聲明瞭一個void函數。在源文件中,我已經爲此函數編寫了實現。在編譯項目時,我收到一個錯誤,指出我的實現與頭中的原型不匹配。C++ void函數試圖返回一個int?
在頭文件(Dictionary.h)代碼顯示爲:
void spellCheck(ifstream checkFile, string fileName, std::ostream &out);
源文件(Dictionary.cpp)中的代碼顯示爲:
Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
_report.setFileName(fileName);
string end = "\n";
int words = 0;
int wrong = 0;
string word;
char currChar;
while(checkFile >> word){
currChar = checkFile.get();
while(currChar != "\\s" && currChar == "\\w"){
word += currChar;
currChar = checkFile.get();
}
out << word << end;
word.clear();
}
/*
_report.setWordsRead(words);
_report.setWordsWrong(wrong);
_report.printReport();
*/
}
有什麼在這裏這可能表明我試圖返回一個整數值?
確切的錯誤是:
Dictionary.cpp:31:1: error: prototype for 'int Dictionary::spellCheck(std::ifstream, std::string, std::ostream&)' does not match any in class 'Dictionary'
Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
^
In file included from Dictionary.cpp:8:0:
Dictionary.h:21:10: error: candidate is: void Dictionary::spellCheck(std::ifstream, std::string, std::ostream&)
void spellCheck(ifstream checkFile, string fileName, std::ostream &out);
^
非常感謝您!我完全錯過了! – CreasyBear
如果這解決了您的問題,將其標記爲已接受,您和問題的回答者都將受益 – rlam12