Consider the following:
template<typename X>
struct Z {};
struct A
{
using Z = ::Z<int>;
struct B : Z
{
using C = Z;
};
};
This compiles fine. Nice. But now add another parameter in Z
:
template<typename X, typename Y>
struct Z {};
struct A
{
template<typename X>
using Z = ::Z<X, int>;
struct B : Z<B>
{
using C = Z<B>; // error: too few template arguments for class template 'Z'
};
};
Ok, maybe it makes sense that the definition of template alias Z
in class A
is visible when deriving nested class B
, but not inside its body, triggering the error since the global definition of Z
has two parameters.
But why is the behavior different in the first case, when Z
is just a type alias in A
?
Finally, make A
a template:
template<typename X, typename Y>
struct Z {};
template<typename T>
struct A
{
template<typename X>
using Z = ::Z<X, int>;
struct B : Z<B>
{
using C = Z<B>;
};
};
Now the error is gone. Why?
(Tested on Clang 3.6 and GCC 4.9.2)
A
stopped being a template, which I thought would simplify the code a lot. However, I am now forced to use two different names for the twoZ
's, which only makes the code uglier. If there is any better workaround, please let me know. – Blackfellow