Bipolo
Bipolo

Reputation: 113

Define type alias between template and class declaration in order to inherent from it

I have a class template which uses some type alias through its implementation, and also inherits from the same type:

template<typename TLongTypename, 
         typename TAnotherLongTypename, 
         typename THeyLookAnotherTypename>
class A : SomeLongClassName<TLongTypename, 
                           TAnotherLongTypename,
                           THeyLookAnotherTypename>
{
    using Meow = SomeLongClassName<TLongTypename, 
                                   TAnotherLongTypename, 
                                   THeyLookAnotherTypename>;
    
    // ... (using Meow a lot)
};

Naturally I want to inherit from the type alias Meow and not from the long name. Is there any nice way to do that, hopefully such that Meow will be defined inside the template scope but before the class scope?

Upvotes: 0

Views: 192

Answers (1)

cigien
cigien

Reputation: 60440

You could declare the type alias Meow as a default template parameter, directly in the template parameter list, which means you only have to spell it out once:

template<typename TLongTypename, 
         typename TAnotherLongTypename, 
         typename THeyLookAnotherTypename,
         // declare Meow once here 
         typename Meow = SomeLongClassName<TLongTypename, 
                                           TAnotherLongTypename,
                                           THeyLookAnotherTypename>>
class A : Meow   // inherit
{
    Meow X;   // use
};

Upvotes: 2

Related Questions