无法将“bool”转换为“NEDElement*”
Cannot convert ‘bool’ to ‘NEDElement*’
在安装 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 * type,有时返回bool。
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 版了。
请帮忙。
问题是它试图将布尔值转换为指针。您可以强制转换它,但我建议改为执行其他失败案例所做的事情:将 return false;
更改为 return 0;
(或者更好,但与其他 return nullptr;
略有不同)。
在安装 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 * type,有时返回bool。
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 版了。
请帮忙。
问题是它试图将布尔值转换为指针。您可以强制转换它,但我建议改为执行其他失败案例所做的事情:将 return false;
更改为 return 0;
(或者更好,但与其他 return nullptr;
略有不同)。