Reputation: 717
How to refer to an alias template of a class A
given as a template parameter to a class C
that inherits from a template base class B
?
#include <vector>
struct A
{
// the alias template I want to refer to:
template<class T>
using Container = std::vector<T>;
};
// the base class
template<template<class> class _Container>
struct B
{
_Container<int> m_container;
};
template<class _A>
struct C : public B< typename _A::Container >
{// ^^^^^^^^^^^^^^^^^^^^^^
};
int main()
{
C<A> foo;
}
I tried several solution by adding the template
keyword at every possible place in the statement (like template<class T> typename _A::Container<T>
, typename _A::template Container
...) but g++
gives either "template argument 1 is invalid" or "type/value mismatch"!
Upvotes: 2
Views: 87
Reputation: 172964
The correct syntax would be:
template <class A>
struct C : public B< A::template Container >
{
};
BTW: Don't use _A
as the name of template parameter, identifiers beginning with an underscore followed immediately by an uppercase letter is reserved in C++.
Upvotes: 5