无法将'bool'转换为'NEDElement *'

问题描述 投票:0回答:1

在安装Omnetpp的过程中,在最后一步“ make”中,我遇到了一个错误,提示:

**`cannot convert ‘bool’ to ‘NEDElement`**  
 in return  np->getErrors()->addError("", "unable to allocate work memory"); return false;}
Makefile:51: recipe for target '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/out/gcc-release/src/nedxml/ned2.tab.o' failed
make[2]: *** [/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/out/gcc-release/src/nedxml/ned2.tab.o] Error 1
make[2]: Leaving directory '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/src/nedxml'
Makefile:96: recipe for target 'nedxml' failed
make[1]: *** [nedxml] Error 2
make[1]: Leaving directory '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2'
Makefile:19: recipe for target 'allmodes' failed
make: *** [allmodes] Error 2

相应的函数如下,其中有时返回类型NEDElement *类型,有时返回布尔值。

NEDElement *doParseNED2(NEDParser *p, const char *nedtext)
{
#if YYDEBUG != 0      /* #if added --VA */
    yydebug = YYDEBUGGING_ON;
#endif

    NONREENTRANT_NED_PARSER(p);

    // reset the lexer
    pos.co = 0;
    pos.li = 1;
    prevpos = pos;

    yyin = NULL;
    yyout = stderr; // not used anyway

    // alloc buffer
    struct yy_buffer_state *handle = yy_scan_string(nedtext);
    if (!handle)
        {np->getErrors()->addError("", "unable to allocate work memory"); return false;}

    // create parser state and NEDFileElement
    resetParserState();
    ps.nedfile = new NedFileElement();

    // store file name with slashes always, even on Windows -- neddoc relies on that
    ps.nedfile->setFilename(slashifyFilename(np->getFileName()).c_str());
    ps.nedfile->setVersion("2");

    // storing the start and end position of the whole file for the NedFileElement
    // NOTE: we cannot use storePos() because it strips off the leading spaces
    // and comments from the element.
    YYLTYPE pos = np->getSource()->getFullTextPos();
    NEDSourceRegion region;
    region.startLine = pos.first_line;
    region.startColumn = pos.first_column;
    region.endLine = pos.last_line;
    region.endColumn = pos.last_column;
    ps.nedfile->setSourceRegion(region);

    // store file comment
    storeFileComment(ps.nedfile);

    ps.propertyscope.push(ps.nedfile);

    globalps = ps; // remember this for error recovery

    if (np->getStoreSourceFlag())
        storeSourceCode(ps.nedfile, np->getSource()->getFullTextPos());

    // parse
    try
    {
        yyparse();
    }
    catch (NEDException& e)
    {
        yyerror((std::string("error during parsing: ")+e.what()).c_str());
        yy_delete_buffer(handle);
        return 0;
    }

    if (np->getErrors()->empty())
    {
        // more sanity checks
        if (ps.propertyscope.size()!=1 || ps.propertyscope.top()!=ps.nedfile)
            INTERNAL_ERROR0(NULL, "error during parsing: imbalanced propertyscope");
        if (!ps.blockscope.empty() || !ps.typescope.empty())
            INTERNAL_ERROR0(NULL, "error during parsing: imbalanced blockscope or typescope");
    }
    yy_delete_buffer(handle);

    return ps.nedfile;
}

我在互联网上搜索了它,但是发现,您应该具有最新的gcc版本,但已经有gcc版本7.5。

请帮助。

gcc makefile bison omnet++
1个回答
0
投票

问题是它试图将布尔值转换为指针。您可以强制使用强制转换,但是我建议改用其他失败案例:将return false;更改为return 0;(或更好,但与其他案例略有不同,return nullptr;)。

© www.soinside.com 2019 - 2024. All rights reserved.