编译器错误:">"标记之前的预期主表达式
compiler error: expected primary-expression before '>' token
#include <string>
...
template <typename DefinitionsIterator>
void parse(const CIET_NS ::VariadicArguments& argumentList, DefinitionsIterator firstDef, DefinitionsIterator lastDef, Map& res)
{
for (int i = 0; i < argumentList.size(); ++i) {
CIET_NS ::Object obj = argumentList.at(i);
std::string objStr = obj.convert<std::string>();
qDebug() << objStr.c_str();
//qDebug() << argumentList.at(i).convert<std::string>().c_str();
}
这段代码可以编译,但是注释的那行不能。我得到这个错误
error: expected primary-expression before '>' token
这怎么可能发生?
template <typename ChildClass, typename ListElementType, typename DuplicateType>
class BasicObject
{
public:
BasicObject();
~BasicObject();
public:
Tcl_Obj* tclObject() const;
Tcl_Obj* releaseObject();
template <typename T>
T convert(Interpreter& interp) const;
template <typename T>
T convert() const;
Object
来源于BasicObject
Compiler version:
g++ -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)
当convert
是模板时,您必须指出(类似于使用typename
表示名称是类型)
qDebug() << argumentList.at(i).template convert<std::string>().c_str();
^^^^^^^^
否则,编译器认为<
是一个比较,当看到>
在可以比较的东西之前时,会感到困惑。
你的编译器是古老的——基于你提供的数据,它是GCC 3.4.6与RHEL4一起发布的,它在几年前被供应商EOLed(是的,现在它处于"延长生命周期"直到2015年,这意味着你真的,真的不应该在上面部署新的应用程序)。
最古老的GCC版本应该与任何支持的Qt版本一起工作是GCC 4.2(在特殊情况下)和GCC 4.4(用于Qt 4.7)。你的编译器有一个bug。为什么需要在这样一个不能编译有效c++代码的陈旧平台上进行部署?
相关文章:
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++ 标记之前预期主表达式'('错误
- 正则表达式中带有卷轴大括号的正则表达式错误
- C++初学者错误:主要表达式错误
- 代数树表达式C++错误:未解析的外部符号"Public:_thiscall AlgebraicTreeExpression::~AlgebraicTreeExpression(void) ..."
- 使用多线程处理对象数组 - 无效使用 void 表达式错误
- 为什么 if constexpr 不会使这个核心常量表达式错误消失?
- 提升正则表达式错误:未初始化的提升::match_results
- C++比较表达式错误
- C++ "主表达式"错误
- C++ 正则表达式错误(未处理的异常)
- 'this'不能用于常量表达式错误 (C++)
- 代码块引发有关for_each的预期主表达式错误
- Boost Regex中的命名子表达式错误
- C++之前的主要表达式错误
- Ubuntu 上的正则表达式错误
- C++正则表达式错误
- 理解常量表达式错误
- 成员函数和预期的主表达式错误
- Xcode中应有表达式错误