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

时间:2015-11-30 23:53:37

标签: c++ compiler-errors

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

头文件(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);
      ^

1 个答案:

答案 0 :(得分:6)

您在这里错过Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){

int

所以你隐式将函数定义为返回void Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){

应该是:

System.currentTimeMillis