8

I'm still trying to migrate from MSVC to GCC, but I can't seem to find a solution to the following problem:

template < typename A, typename B, typename C, typename D >
class Test
{
public:
    Test (B* pObj, C fn, const D& args) : _pObj(pObj), _fn(fn), _args(args)
    {
    }

    A operator() ()
    {
        return _args.operator() < A, B, C > (_pObj, _fn); // error: expected primary-expression before ',' token
    }

    B* _pObj;
    C _fn;
    D _args;
};

Please help!

Ryan
  • 1,451
  • 2
  • 27
  • 36

1 Answers1

23

Try return _args.template operator() < A, B, C > (_pObj, _fn);.

Without the template keyword the parse would be different. Without that extra use of template, the compiler does not know that the less-than token (<) that follows is not really "less than" but the beginning of a template argument list.

14.2/4

When the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.

P.S: Read this Stackoverflow FAQ Entry

Community
  • 1
  • 1
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
  • 1
    Thank you very much! I knew about template keyword, but I never thought about using it in method declaration... Now I get it, thanks! – Ryan Apr 27 '11 at 10:25
  • Thanks from me too, I'd forgotten completely about this. This solved a similar problem I had! Upvoted. – DNT May 29 '15 at 18:32