Reputation: 65
I have a header file in which a void function is declared. In the source file I have written implementation for this function. Upon compiling the project I receive an error indicating that my implementation does not match a prototype in the header.
The code in the header file (Dictionary.h) appears as:
void spellCheck(ifstream checkFile, string fileName, std::ostream &out);
The code in the source file (Dictionary.cpp) appears as:
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();
*/
}
Is there anything here that might indicate that I have tried to return an integer value?
The exact error is:
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);
^
Upvotes: 0
Views: 106
Reputation: 212979
You are missing a void
here:
Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
so you are implicitly defining the function as returning int
.
It should be:
void Dictionary::spellCheck(ifstream checkFile, string fileName, std::ostream &out){
Upvotes: 6