我想知道如何理解下面的模板定义。你能给我解释一下吗?
// First, we define some factory functions for creating instances of
// the implementations. You may be able to skip this step if all your
// implementations can be constructed the same way.
template <class T>
PrimeTable* CreatePrimeTable();
template <>
PrimeTable* CreatePrimeTable<OnTheFlyPrimeTable>() {
return new OnTheFlyPrimeTable;
}
template <>
PrimeTable* CreatePrimeTable<PreCalculatedPrimeTable>() {
return new PreCalculatedPrimeTable(10000);
}
我只知道 C 模板函数是这样定义的:
template <Type A, Type B>
func(A a, B b) {
//do some operation with a and b;
}
它应该与以下定义相同吗?
template <class T>
PrimeTable* CreatePrimeTable(){
return new T;
}
非常感谢您的帮助。
谢谢