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 7128433
In Process

The Archive Base Latest Questions

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

In a portion of legacy code that I have been asked to work with,

  • 0

In a portion of legacy code that I have been asked to work with, I have come across a concept that I don’t understand. Searching in SO and googling didn’t quite help, hence this question.

There is a template class that looks like this:

template<int Index_t, int Kind_t, ProtocolType Prot_t, class Protocol>
class CommandHandlerGeneric 
   : private CommandHandlerGeneric<Index_t-1, Kind_t, Prot_t, Protocol> {
public:
   CommandHandlerGeneric(Protocol& Shared, CmdHandlerBase** Cont) :
      CommandHandlerGeneric<Index_t-1, Kind_t, Prot_t, Protocol>(Shared, Cont) {}
};

The CmdHandlerBase class is a non-template class that exists elsewhere in a different header. Following the above definition, there is a macro that looks like this:

#define REGISTER_COMMAND_HANDLER_BASE(CmdIndex, CmdType, CmdKind, ProtType) \
    template<class Protocol> \
    class CommandHandlerGeneric<CmdIndex, CmdKind, ProtType, Protocol>
       : private CommandHandlerGeneric<CmdIndex-1, CmdKind, ProtType, Protocol> \
    { \
       CmdType m_Cmd;\
     public: \
       CommandHandlerGeneric(Protocol& Shared, CmdHandlerBase** Cont) : \
         m_Cmd(Shared), \
         CommandHandlerGeneric<CmdIndex-1, CmdKind, ProtType, Protocol>(Shared, Cont) \
       { Cont[CmdIndex] = &m_Cmd; } \
    };

Looks like the above macro partially specializes the class template CommandHandlerGeneric. Is this correct? What is the rationale behind deriving a class privately from itself?

  • 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:08:18+00:00Added an answer on May 28, 2026 at 11:08 am

    I can’t really make anything of your specific example, but in general, that is a recursive class-template. There should be a specialization around for Index_t = x, which would terminate the recursion.

    The second ingredient here is private inheritance, which can be thought of as a form of composition. Combined with a recursive template, you can use this to create a class of variable sizes, for instance a vector of a certain dimension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some legacy code that provides a list of the available COM ports
I have a portion of code that is dynamically loaded via an AJAX call
I have a portion of my data that has been parsed incorrectly (due to
A very small portion of our codebase is some legacy Java code. I'm trying
I have a portion of a bash script that is getting a filename without
I'd like to reserve a portion of the screen so that maximized windows don't
I have a legacy JSF application. Now that we want to add i18n support
Here's the encryption portion of my code. It compiles fine but fails with that
this portion of code is outputing 01/01/1970. is my code incorrect? i have only
Having trouble getting one portion of my code to work. Building a rudimentary linked

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.