【发布时间】:2015-12-01 01:29:46
【问题描述】:
我的问题是: 错误是否恰好出现在未忽略 void 值的位置,还是出现在内部发生此错误的函数调用中?
例如,我遇到的具体问题...
在我的main.cpp 中,我有以下声明和函数调用:
Dictionary * D = new Dictionary(&dictionaryFile, dictionaryName);
ifstream checkFile;
...
*D->spellCheck(&checkFile, fileName, &cout);
这里的函数调用给出了错误:
“错误:应忽略的无效值”
这个特定的函数调用是在尝试使用 void 值还是在 Dictionary.cpp 中定义如下的函数内:
void 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 != ' ' && currChar != ',' && currChar != '.'){
word += currChar;
currChar = checkFile->get();
}
*out << word << end;
word.clear();
}
/*
_report.setWordsRead(words);
_report.setWordsWrong(wrong);
_report.printReport();
*/
}
提前非常感谢!
【问题讨论】:
-
尝试将
*D->spellCheck更改为D->spellCheck。 -
仅此而已!谢谢!
-
运算符优先级使得一元
*运算符适用于子表达式D->spellCheck(&checkFile, fileName, &cout),从而产生void结果。(*D).spellCheck(&checkFile, fileName, &cout)也可以,但D->spellCheck(...)更惯用。
标签: c++ compiler-errors