0

If I have a templated storage class, how can I create a specialized template for nested storage class. I already know how to specialize pointer template, but I don't know how to specialize this. EG:

template <typename Type>
class Array
{
///Array class code
};
int main()
{
    Array<int> rob;
    Array<Array<int> > bob;//I need bob to be specialized, but not rob
    return 0;
}

Is this possible?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Narue
0

You can still use the template parameter for a nested type:

#include <iostream>

template <typename Type>
class Array {
public:
    Array() { std::cout<<"Default Array<>\n"; }
};

template <typename Type>
class Array<Array<Type> > {
public:
    Array() { std::cout<<"Specialized Array<>\n"; }
};

int main()
{
    Array<int> rob;
    Array<Array<int> > bob;
}

It only gets tricky if you need to generalize both parameter types (vector instead of Array, and double instead of int, for example).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.