0

I ran to some problems with c++11 alias templates. As you can see below, I want to create an alias to A::B from class C. Before instantiation is made the compiler (gcc 6.1) cannot assert that V has a member type B, therefore giving the error:

error: expected ‘;’ before ‘<’ token  
template<typename ValueT> using B = typename V::B<ValueT>;

Does not his go against the usual way templates are dealt with in C++, that is assuming that the template type provides all necessary functionalities until proven otherwise by an instantiation?

template<typename T> class A{
    T a;
public:
    template <typename ValueT> class B {
        ValueT b;
    };
};

template <typename V = A<int>> class C {
public:
    template<typename ValueT> using B = typename V::B<ValueT>;
};
S. K.
  • 433
  • 3
  • 9
  • 2
    `template using B = typename V::template B;` – n. m. could be an AI Nov 01 '16 at 06:01
  • Thanks. I didn't see the duplicate question. I can't believe that after all those long years of C/C++ programming I can still get fooled by the syntax. Also, compilers' messages when it comes to templates are useless at best, misleading in the worst case. – S. K. Nov 01 '16 at 07:04
  • As a side note, clang gives much better explanation of the problem: "error: use 'template' keyword to treat 'B' as a dependent template name" – Dmitry Nov 01 '16 at 11:36

0 Answers0