I have a template class that I have some specializations for.
But the next specialization is a template itself. How do you specify this:
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";}
}
Trivial partial specialization ?
template <typename T>
class Action<std::vector<T>> {
public:
void doStuff() { std::cout << "A Generic Vector\n"; }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With