繁体   English   中英

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

[英]C++ void function trying to return an int?

我有一个头文件,其中声明了一个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);
      ^

您在这里缺少void

Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){

因此,您将函数隐式定义为返回int

它应该是:

void Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM