为什么这段代码不能编译?
struct A {
template <class T>
static T a(int i) { return 2*i; }
};
template <class T>
struct B {
double b;
B(): b(T::a<double>(5)) {}
};
template class B<A>;
Run Code Online (Sandbox Code Playgroud)
编译器甚至没有到达模板实例化.我正在使用gcc 4.7.0.
test.cc: In constructor »B<T>::B()«:
test.cc:9:25: Error: expected »(« before »<« token
test.cc:9:26: Error: expected primary-expression before »double«
Run Code Online (Sandbox Code Playgroud)
你错过了一个template关键字,因为它a是一个从属名称(或类似的东西).
B(): b(T::template a<double>(5)) {}
Run Code Online (Sandbox Code Playgroud)
(也是你的最后一行应该template struct B<A>;.)
有关血腥的详细信息,请参阅: 我必须在何处以及为何要使用"模板"和"typename"关键字?
| 归档时间: |
|
| 查看次数: |
144 次 |
| 最近记录: |