Is it possible to inherit a specialized struct/class like following?
template<class TKey, class TData>
struct Container
{
virtual void Add(TKey key, TData data) = 0;
};
template<class TData>
struct Container<int, TData>
{
virtual void Add(int key, TData data) = 0;
};
struct TicketContainer : public Container<std::string>
{
void Add(int key, std::string data)
{
}
};
I am getting errors in TicketContainer declaration complaining too few template parameters declared.
Change:
to:
or some other type for
TKey.Even though you have provided a partial specialization of
Containeryou still need to specify both of the template parameters.You can specify default types for template parameters if you do not want to specify both template parameters. In this case, you would have to reorder
TKeyandTValue(which may be counter intuitive as associative containers are normally declaredkeythenvalue):