How do I extract the template type from a class:
for example, I have a class like:
template <typename T, typename T2 = def>
class A
{
typedef T type;
typedef T2 type2;
//other stuff
}
And I want to use type2 in other templates:
template <typename G>
foo(A<G> a)
{
//This doesn't work:
std::vector<a::type2> vec;
//Neither does this:
std::vector<a->type2> vec;
//or this:
std::vector<typename a::type2> vec;
}
So how do I figure out what type2 is for the instance a (can a have a value for type2 that isn’t the default)?
This should work:
Reason:
std::vectorexpects a complete type as its argument, and justAis atemplate, butA<G>becomes a complete type. From your example, I have mentionedA<G>, but it can beA<int>,A<char>anything.