开发者

Ugly compiler errors with template

开发者 https://www.devze.com 2023-02-11 21:39 出处:网络
template<typename T> struct function { typedef T type; template<typename U> static void f() {}
template<typename T>
struct function
{
   typedef T type;
   template<typename U>
   static void f() {}
};

template<typename T>
struct caller
{
        int count;
        caller(): count() {}
        void operator()()
        {
                count++;
                T::f<typename T::type开发者_开发问答>();
        }
};

int main() {
        caller<function<int> > call;
        call();
        return 0;
}

This seems correct to me, but compiler gives this ugly error which I am unable to understand:

prog.cpp: In member function ‘void caller::operator()()’:

prog.cpp:17: error: expected `(' before ‘>’ token

prog.cpp:17: error: expected primary-expression before ‘)’ token

For your convinence, code is posted here -> http://www.ideone.com/vtP7G


T::template f<typename T::type>();

Without this "template", the code is parsed as:

T::f [less-than operator] typename T::type [greater-than operator]...

Which is an error.

0

精彩评论

暂无评论...
验证码 换一张
取 消