Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a private inherited inner template public via a using directive

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?

like image 846
vsoftco Avatar asked May 27 '15 20:05

vsoftco


1 Answers

Not possible. A using-declaration is, from [namespace.udecl]:

using typenameoptnested-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;
};
like image 61
Barry Avatar answered Nov 02 '22 10:11

Barry