在Ubuntu中编译C++项目时,其中GCC版本是7.4.0,调用模板函数的地方会报如下错误
error: expected primary-expression before ‘>’ token this->pCmd = this->pBuffer->constructTail<CmdT>(); error: expected primary-expression before ‘)’ token this->pCmd = this->pBuffer->constructTail<CmdT>(); error: expected primary-expression before ‘>’ token this->pCmd = this->buffer.constructTail<CmdT>(); error: expected primary-expression before ‘)’ token this->pCmd = this->buffer.constructTail<CmdT>();
问题原因:在调用模板函数时,解析器无法分辨>是一个模板参数的起始符号还是一个比较操作符;所以需要使用关键词告诉解析器这是一个模板参数的起始符号
解决方法:
this->pCmd = this->pBuffer->template constructTail(); this->pCmd = this->pBuffer->template constructTail(); this->pCmd = this->buffer.template constructTail(); this->pCmd = this->buffer.template constructTail();
- 本文固定链接: http://jingyan.idoubi.net/1734.html
- 转载请注明: 游戏创作者大陆 于 逗分享开发经验 发表