我有一個模板類,我有一些專業化的。
但下一個專業化是模板本身。你如何指定這個:專業化本身就是一個模板
template<typename T>
class Action
{
public: void doStuff() { std::cout << "Generic\n"; }
}
// A specialization for a person
template<>
class Action<Person>
{
public: void doStuff() { std::cout << "A Person\n";}
}
// I can easily specialize for vectors of a particular type.
// But how do I change the following so that it works with all types of vector.
// Not just `int`
template<>
class Action<std::vector<int> >
{
public: void doStuff() { std::cout << "A Generic Vector\n";}
}
我只是想知道你不知道這個! – Nawaz 2012-01-16 08:16:28
@Nawaz:我的想法,也許是深夜吧? – 2012-01-16 08:24:28
現在我明白了答案,但我一直在其中添加另一個模板行。 – 2012-01-16 18:47:20