相关疑难解决方法(0)

从模板函数调用的模板类的模板成员函数

这不编译:

template<class X> struct A {
   template<int I> void f() {}
};

template<class T> void g()
{
   A<T> a;
   a.f<3>();  // Compilation fails here (Line 18)
}

int main(int argc, char *argv[])
{
   g<int>();  // Line 23
}
Run Code Online (Sandbox Code Playgroud)

编译器(gcc)说:

hhh.cpp:在函数'void g()'中:

hhh.cpp:18:错误:')'令牌之前的预期primary-expression

hhh.cpp:在函数'void g()[with T = int]'中:

hhh.cpp:23:从这里实例化

hhh.cpp:18:错误:无效使用成员(你忘了'&'?)

谁能解释为什么会这样?有没有办法让它发挥作用?

c++ templates

45
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

templates ×1