10

私はいくつかの専門分野を持つテンプレート クラスを持っています。
しかし、次の特化はテンプレートそのものです。これをどのように指定しますか:

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";}
}
4

1 に答える 1

19

些細な部分特化?

template <typename T>
class Action<std::vector<T>> {
public:
  void doStuff() { std::cout << "A Generic Vector\n"; }
};
于 2012-01-16T07:30:09.380 に答える