我有一个名为Managed
的模板类,它具有静态模板create()
函数。我试图编写一个帮助程序,在传递Managed子类类型时返回该函数。
typedef std::function<ScreenBase::ptr (WindowBase&)> ScreenFactory;
template<typename T>
ScreenFactory screen_factory() {
ScreenFactory ret = &T::create<WindowBase&>;
return ret;
}
因为create本身需要模板参数,所以我明确地尝试获取对带有WindowBase&amp;的实例化的引用。据我所知,上面的代码应该可行。
然而,当我尝试调用它时,我收到以下错误:
error: expected '(' for function-style cast or type construction
ScreenFactory ret = &T::create<WindowBase&>;
~~~~~~~~~~^
我不确定我做错了什么,有什么指针?
答案 0 :(得分:4)
您缺少template
个关键字:
template<typename T>
ScreenFactory screen_factory() {
ScreenFactory ret = &T::template create<WindowBase&>;
// ~~~~~~~^
return ret;
}
有关详情,请参阅Where and why do I have to put the “template” and “typename” keywords?