C++ void函数试图返回一个int?

Cre*_*ear 0 c++ compiler-errors

我有一个头文件,其中声明了一个void函数.在源文件中,我已经为此函数编写了实现.在编译项目时,我收到一个错误,指示我的实现与标头中的原型不匹配.

头文件(Dictionary.h)中的代码显示为:

void spellCheck(ifstream checkFile, string fileName, std::ostream &out);
Run Code Online (Sandbox Code Playgroud)

源文件(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();
    */
}
Run Code Online (Sandbox Code Playgroud)

这里有什么可能表明我试图返回一个整数值吗?

确切的错误是:

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);
      ^
Run Code Online (Sandbox Code Playgroud)

Pau*_*l R 6

你错过了一个void:

Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
Run Code Online (Sandbox Code Playgroud)

所以你隐式将函数定义为返回int.

它应该是:

void Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
Run Code Online (Sandbox Code Playgroud)