2

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"!

T.L
  • 595
  • 3
  • 16

1 Answers1

5

The correct syntax would be:

template <class A>
struct C : public B<   A::template Container  >
{
};

LIVE

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++.

songyuanyao
  • 169,198
  • 16
  • 310
  • 405