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

  • Home
  • SEARCH
  • 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 8686659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:54:37+00:00 2026-06-12T22:54:37+00:00

I have a question about a code that I have recently took in my

  • 0

I have a question about a code that I have recently took in my hands. I just want to know if in C++ templates paradigm it is correct or useful to do the following inheritance (just 3 classes as an example):


template< class I, class P, class D, unsigned int ID = 0 >
class PathFilter : public Filter< I, P, 1 >
{
...
}

template< class I, class A, unsigned int N = 1 >
class Filter : public Algorithm< I, A >
{
...
}

template< class I, class A >
class Algorithm : public A //This line
{
   ...
}

My question is specifically about the inheritance in the third example. Is it useful to make it so ‘generic’ and not precise? It is a good choice to compromise understandable code by a more generic code?

I ask firstly because I’m not an expert in C++ templates, but also because I see this code difficult to understand using templates (usually the names of the templates say nothing about its content). Any advice?

  • 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-06-12T22:54:40+00:00Added an answer on June 12, 2026 at 10:54 pm

    What you are doing is a mixin class (in particular, your class Algorithm is the one).

    As a reference you can consult, for instance, http://en.wikipedia.org/wiki/Mixin or http://en.wikipedia.org/wiki/Composite_pattern.

    Indeed you are specifying “certain functionality (specified by A) to be inherited or just reused by a subclass (i.e. Algorithm)”. (cit. from the first article)

    In other words, you are making yourself (or your user) free to add or change behavior to Algorithm somehow “afterwards”. Your real gain is to achieve such a flexibility relying just on the compiler and not on some dynamic-binding-like mechanism (e.g. overriding of virtual functions). Your final class Algorithm<A>, in fact, is built at compile time and it is possibly as efficient as the class you would have obtained writing Algorithm<A> explicitly (i.e. explicitly including the policy A in Algorithm writing it by hand).

    EDIT:

    I would also suggest to give a look to this wikipedia page about policy based design ( http://en.wikipedia.org/wiki/Policy-based_design ).

    There, policies names (your A) appear in a clear form, with clear names, as wisely advised by @full.stack.ex.

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

Sidebar

Related Questions

Quick question about include/requre_once . I have some code that is common to a
So I just have posted a question about this code (which was answered): $(document).ready(Main);
I have a question about the following code in TCL/EXPECT: expect { timeout {
I have a question about the following code : #include <iostream> #include <ctime> int
I have a question about the following C code: void my_function() { int i1;
I have a question about defining Foreign Key in EF Code First Fluent API.
I have a question about a programming problem from the book Cracking The Code
I have a question about how GC works in Java. Consider the following code:
I have a question about variable scope in TCL, I have the following code:
i have what i hope is a quick question about some code i am

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.