【发布时间】:2017-03-27 18:55:28
【问题描述】:
我想用一个基类的模板函数,像这样:
struct A {
template <class T> static auto f() { \*code*\ }
};
template <class A_type> struct B : public A_type {
using A_type::f;
void g() { auto n = f<int>(); }
};
然而这并不能编译。
error: expected '(' for function-style cast or type
construction
void g() { auto n = f<int>(); }
~~~^
error: expected expression
void g() { auto n = f<int>(); }
但是直接引用基类而不是模板确实有效:
struct A {
template <class T> static auto f() { \*code*\ }
};
template <class A_type> struct B : public A_type {
using A::f;
void g() { auto n = f<int>(); }
};
为什么第一个版本不能编译,而第二个版本可以。我需要做些什么不同的事情才能让它发挥作用?
【问题讨论】:
标签: c++ templates inheritance using-statement