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