I'm trying to use a using
directive to bring in the public
access declaration of a derived class some inner class template declared in the base. Code:
template <typename T>
class Base
{
public:
template<typename U>
struct Inner;
};
template<typename T>
class Derived: private Base<T>
{
public:
using typename Base<T>::template Inner; // make it visible
Inner<T>* ptr; // no need for typename here, non-qualified name
};
int main() {}
Neither g++ nor clang++ compile this code, both complaining about
error: expected unqualified-id before 'template'
As far as I know, Inner
is a dependent template name, so one should use ::template
when qualifying its name, and also a typename
before, since Base<T>::Inner
is a dependent type. I've tried all possible combinations with/without typename/template
, and none compile. Is there any way of using Inner
in the public
section of Derived
?
Not possible. A using-declaration is, from [namespace.udecl]:
using
typename
optnested-name-specifier unqualified-id ;
But an unqualified-id can't be a class template.
You could just make an alias instead:
template<typename T>
class Derived: private Base<T>
{
public:
template <typename U>
using Inner = typename Base<T>::template Inner<U>;
Inner<T>* ptr;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With