Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7130047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:18:30+00:00 2026-05-28T11:18:30+00:00

C++03 allows to create template class which inheritances from template parameters: // c++03 struct

  • 0

C++03 allows to create template class which inheritances from template parameters:

// c++03 

struct NullType {};

template <class T0, class T1 = NullType, class T2 = NullType>
class Collector : public T0, public T1, public T2
{
};

template <class T0, class T1>
class Collector<T0, T1, NullType> : public T0, public T1
{
};

template <class T0>
class Collector<T0, NullType, NullType> : public T0
{
};

So

typedef Collector<A, B, C> X;

eqeals to

class X: public A, public B, public C {};

C++11 allows do it easier:

// variadic templates - great thing!
template <class ... Classes>
class C11_Collector :
    public Classes ...
{
};

Wrapping collector must wraps template parameters before inheritence:

template <template <class> class Wrap, class T0, class T1 = NullType, class T2 = NullType>
class Wrapping_Collector : public Wrap<T0>, public Wrap<T1>, public Wrap<T2>
{
};

template <template <class> class Wrap, class T0, class T1>
class Wrapping_Collector<Wrap, T0, T1, NullType> : public Wrap<T0>, public Wrap<T1>
{
};

template <template <class> class Wrap, class T0>
class Wrapping_Collector<Wrap, T0, NullType, NullType> : public Wrap<T0>
{
};

So

typedef Wrapping_Collector<W, A, B> X;

eqeals to

class X: public W<A>, public W<B> {};

How implement Wrapping_Collector in more easer way by c++11?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:18:30+00:00Added an answer on May 28, 2026 at 11:18 am

    Is it possible to just enforce Wrap<NullType> to be an empty class? Then you could just directly use

    template <template <typename> class Wrap, typename... Types>
    class Wrapping_Collector : public Wrap<Types>... {
       //...
    };
    

    Alternatively, if a double-inheritance chain instead of direct multi-inheritance is fine, you could make Wrapping_Collector<Wrap, A, B...> derive from both Wrapping_Collector<Wrap, B...> and Wrap<A>:

    template <template <typename> class Wrap, typename... Types>
    class Wrapping_Collector;
    
    // The normal case
    template <template <typename> class Wrap, typename Head, typename... Rest>
    class Wrapping_Collector<Wrap, Head, Rest...>
        : public Wrapping_Collector<Wrap, Rest...>, Wrap<Head>
    {
        //...
    };
    
    // Ignore on NullType
    template <template <typename> class Wrap, typename... Rest>
    class Wrapping_Collector<Wrap, NullType, Rest...>
        : public Wrapping_Collector<Wrap, Rest...>
    {
        //...
    };
    
    // Base case
    template <template <typename> class Wrap>
    class Wrapping_Collector<Wrap> {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flex app which allows user to create some content. this content
In Perl there is a very handy module, Term::VT102, which allows you to create
I need to create Perl code which allows counting paragraphs in text files. I
I need to create a cross-site template object which will check the current time
class base { int a; protected: template<class T> class derived; public: base() {} virtual
Can lambda expressions be used as class template parameters? (Note this is a very
Prototype's Template class allows you to easily substitute values into a string template. Instead
Xcode allows you to create automated scripts for performing repetitive tasks. What scripts have
I have an app that allows you to create Home shortcuts to a specific
I am working on a Rails app that allows you to create a configuration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.