Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板中的编译器错误 模板 结构函数 { T型; 模板 静态void f(){} }; 模板 结构调用程序 { 整数计数; 调用方():计数(){} void运算符()() { 计数++; T::f(); } }; int main(){ 来电; call(); 返回0; }_C++_Templates - Fatal编程技术网

C++ 模板中的编译器错误 模板 结构函数 { T型; 模板 静态void f(){} }; 模板 结构调用程序 { 整数计数; 调用方():计数(){} void运算符()() { 计数++; T::f(); } }; int main(){ 来电; call(); 返回0; }

C++ 模板中的编译器错误 模板 结构函数 { T型; 模板 静态void f(){} }; 模板 结构调用程序 { 整数计数; 调用方():计数(){} void运算符()() { 计数++; T::f(); } }; int main(){ 来电; call(); 返回0; },c++,templates,C++,Templates,这对我来说似乎是正确的,但编译器给出了一个我无法理解的丑陋错误: prog.cpp:在成员函数“void caller::operator()”: 程序cpp:17:错误:应为“(”在“>”标记之前 prog.cpp:17:错误:在“')标记之前应该有主表达式 为方便起见,此处发布了代码-> 这是一个错误 template<typename T> struct function { typedef T type; template<typename U>

这对我来说似乎是正确的,但编译器给出了一个我无法理解的丑陋错误:

prog.cpp:在成员函数“void caller::operator()”:
程序cpp:17:错误:应为“(”在“>”标记之前
prog.cpp:17:错误:在“')标记之前应该有主表达式

为方便起见,此处发布了代码->

这是一个错误

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;
}
T::template f<typename T::type>();
T::f [less-than operator] typename T::type [greater-than operator]...