GCC weird error: expected primary expression before ',' token

I am still trying to migrate from MSVC to GCC, but I cannot 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!

+6
source share
1 answer

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

Without the template keyword, parsing would be different. Without this additional use of template compiler does not know that the underlying token (<) that follows is actually not "less", but the beginning of the list of template arguments.

14.2 / 4

When then the member template specification appears. or → in a postfix expression or after a nested qualifier name in identified-id, and postfix-expression or identified-id clearly depends on the template parameter (14.6.2), the participant’s template name must be the keyword template prefix . Otherwise, it is assumed that the name is called a non-pattern.

PS: Read this fooobar.com/questions/11848 / ...

+19
source

Source: https://habr.com/ru/post/886781/


All Articles