Confusing Template error

后端 未结 4 1191
萌比男神i
萌比男神i 2020-12-04 11:44

I\'ve been playing with clang a while, and I stumbled upon \"test/SemaTemplate/dependent-template-recover.cpp\" (in the clang distribution) which is supposed to provide hint

4条回答
  •  心在旅途
    2020-12-04 12:28

    Insert it just before the point where the caret is:

    template struct X {
         void f(T* t)
         {
            t->template f0();
         }
    };
    

    Edit: the reason for this rule becomes clearer if you think like a compiler. Compilers generally only look ahead one or two tokens at once, and don't generally "look ahead" to the rest of the expression.[Edit: see comment] The reason for the keyword is the same as why you need the typename keyword to indicate dependent type names: it's telling the compiler "hey, the identifier you're about to see is the name of a template, rather than the name of a static data member followed by a less-than sign".

提交回复
热议问题