繁体   English   中英

编译器错误:在'>'标记之前的预期primary-expression

[英]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();
                               ^^^^^^^^

否则编译器认为<是比较并且在看到>之前会被混淆,然后才能进行比较。

您的编译器很古老 - 基于您提供的数据,它是随RHEL4一起提供的GCC 3.4.6,几年前由供应商提供EOLed(是的,现在它处于“延长生命周期”,直到2015年,这意味着你真的,真的不应该在那上部署新的应用程序)。

应该与任何支持的Qt版本一起使用的最古老的GCC版本是GCC 4.2(在特殊情况下)和GCC 4.4(对于Qt 4.7)。 你的编译器有bug。 为什么需要在这样一个能够编译有效C ++代码的古老平台上进行部署?

暂无
暂无

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

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