简体   繁体   English

C ++无效值不应该被忽略(不尝试分配无效值...)

[英]C++ void value not ignored as it ought to be (Not trying to assign a void value…)

My question is this: Does the error appear exactly where the void value is not being ignored or can it appear at a function call that had this error occur internally? 我的问题是:该错误是否恰好出现在不忽略void值的地方,或者它是否会出现在内部发生此错误的函数调用中?

For example, the specific problem I am having... 例如,我遇到的特定问题...

In my main.cpp , I have the following declarations and function call: main.cpp ,我具有以下声明和函数调用:

Dictionary * D = new Dictionary(&dictionaryFile, dictionaryName);
ifstream checkFile;
...
*D->spellCheck(&checkFile, fileName, &cout);

The function call here gives the error: 这里的函数调用会出现错误:

"error: void value not ignored as it ought to be" “错误:无效值不应该被忽略”

Is this specific function call trying to use a void value or could it be within the function, which is defined as follows, in Dictionary.cpp: 这个特定的函数调用是尝试使用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();
    */
}

Many thanks in advance! 提前谢谢了!

*D->spellCheck(...) first calls D->spellCheck , then tries to dereference its return value. *D->spellCheck(...)首先调用D->spellCheck ,然后尝试取消引用其返回值。 Since it returns void , you can't dereference the return value. 由于它返回void ,因此您无法取消引用返回值。

Remove the * . 删除*

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

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