Search code examples
c++qttemplatesmingw32qvariant

MinGW calling template from template


I have a very simple function, that will just return the value of a QVariant. It's a part of a class to return the value of the private QVariant data:

template <typename T>
QVariantReference<T>::operator T() const
{
    return this->data.value<T>();
}

If I compile with the MSVC2013-compiler, it just works fine, but if I try to do this with MinGW, i get the following error:

C:\C++Libraries\Qt\workplace\QXmlDataSaver\QXmlDataSaver\qxmldatasaver.h:34: Fehler: expected primary-expression before '>' token
return this->data.value<T>();

I already checked the QVariant-Documentation but there is no hint about compilers regarding this function. I can call QVariant::value<T>() in non-template-functions without any problems.

Anyone an idea what the reason could be? Or is this normal behavior for MinGW? Thanks for your help.


Solution

  • You have to tell the compiler value is a member template. It does not by default assume that it is, and instead parses the first < as the less-than operator. MSVC actually disregards that rule and isn't standard conforming.

    template <typename T>
    QVariantReference<T>::operator T() const
    {
        return this->data.template value<T>();
    }