我目前正在使用template
C++ 中的 s 并被template template parameters
.
可以说我有以下课程:
template<typename T>
struct MyInterface
{
virtual T Foo() = 0;
}
class MyImpl : public MyInterface<int>
{
public:
int Foo() { /*...*/ }
};
template< template<typename T> typename ImplType>
class MyHub
{
public:
static T Foo()
{
ImplType i;
return i.Foo();
}
private:
MyHub() { }
~MyHub() { }
};
从本质上讲,我希望有一个static class
likeMyHub
接受一个实现MyInterface
并提供某些static
方法来使用它们,比如static T Foo()
.
然后我尝试使用MyHub
:
int main()
{
int i = MyHub<MyImpl>::Foo();
return 0;
}
不幸的是,我总是得到一个错误,说T
(static T Foo()
MyHub 中的)类型没有命名类型。
我希望它有效,因为
- 模板参数的模板参数
Impl
命名为T MyHub
是具有一个模板参数并包含一个方法的模板类Foo
到目前为止,在挖掘文档和谷歌结果后,我找不到解决方案,所以我希望你们中的一些人能帮助我。