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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:42:10+00:00 2026-06-04T21:42:10+00:00

In other words: Is it possible to make a template specialisation that inherits from

  • 0

In other words: Is it possible to make a template specialisation that inherits from its base, like this:

template <class T>  
class A{};  
template <>  
class A<int>:public A<>{};  

so that A has all of A’s functions?
I’m new here, so I dunno how to format, just in case the code comes up incorrectly.

  • 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-04T21:42:12+00:00Added an answer on June 4, 2026 at 9:42 pm

    You can, with a bit of trickery. This pattern is sometimes called “template subclassing” and is used extensively in the SeqAn library.

    The trick is to give the base class an additional template argument tag which determines the type identity:

    template <typename T, typename Spec = void>
    struct A { … };
    
    // inheritance tag:
    struct Derived { };
    
    template <typename T>
    struct A<T, Derived> : public A<T, void> { … };
    

    Here, void denotes the base (you could also use a dedicated tag Base but void works fine) and Derived, an empty struct, denotes the derived class.

    Now you can instantiate and use the templates as follows:

    A<int> the_base;
    A<int, Derived> the_derived;
    
    the_base.do_something();
    the_derived.do_something();
    

    For a real-world example, consider the String class from SeqAn:

    String<Dna> some_dna = "GATTACA";
    String<Dna, Packed> more_dna = "GATTACA";
    

    The second type derived from the first one, but is a specialisation which packs its characters as tightly as possible (for DNA, this means putting four DNA characters in each byte).

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

Sidebar

Related Questions

In other words, given a base class shape and a derived class rectangle :
I am attempting to make a class that has a template object member inside
Very simple question, is it possible to make a variable that is retrieved from
I would like to know if its possible, by using JSF, to make somethings
Is it possible to create a MIDP Application for Windows Mobile? In other words,
Is it possible to create a custom dictionary for an edittext? In other words,
In other words, I have a string like: anything, escaped double-quotes: \, yep anything
In other words, can I do something with a volatile variable that could not
I'm trying to make template.render() (import was: from google.appengine.ext.webapp import template ) use a
Is it possible to make a control global (or public) so that every window

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.