简体   繁体   中英

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();

    }

This code compiles but the line commented doesn't. I am getting this error

 error: expected primary-expression before '>' token

How this could be happening?

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 is derived from 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)

When convert is a template, you have to indicate that (similar to using typename to indicate that a name is a type).

qDebug() << argumentList.at(i).template convert<std::string>().c_str();
                               ^^^^^^^^

otherwise the compiler believes that < is a comparison and gets confused when seeing > before something that can be compared.

Your compiler is ancient -- based on the data you provided, it is GCC 3.4.6 which shipped with RHEL4, which got EOLed by the vendor years ago (yes, now it's on an "extended life cycle" until 2015, which means that you are really, really not supposed to be deploying new applications on that).

The oldest GCC version which is supposed to work with any supported version of Qt is GCC 4.2 (under special circumstances) and GCC 4.4 (for Qt 4.7). Your compiler has a bug. Why do you need to deploy on such an archaic platform which canot compile a valid C++ code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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