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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:52:09+00:00 2026-06-08T23:52:09+00:00

I inherit from a template with partial specialization, and I can’t call the template

  • 0

I inherit from a template with partial specialization, and I can’t call the template ctor from the derived ctor.

When the partial specialization in the code below is commented out, it compiles without any errors or warnings.

#include <iostream>
typedef enum {supertype, subtype} selector;

template< typename T, selector s>
class Tmpl {
protected:
    T* root;
public:
    Tmpl( T* t = 0 ) {
        root = t;
    }
    T listHead( ) {
        std::cout << "template listHead() called" << std::endl;
    }
};

class Descriptor {
public:
    Descriptor( const char * s ) {
        std::cout << "Descriptor " << s << std::endl;
    }
};

// partial specialization - if uncommented, errors 
// are reported at the supertypesIterator ctor below.
/*
template<selector s>
class Tmpl<Descriptor, s> {
public:
    Descriptor listHead( ) {
        switch( s ){
            case supertype:
                return Descriptor("Supertypes");
            case subtype:
                return Descriptor("Subtypes");
        }
    }
};
*/

class supertypesIterator : public Tmpl<Descriptor, supertype> {
public:
    supertypesIterator( Descriptor* t = 0 ):Tmpl<Descriptor, supertype>(t) {}
};


main() {
    supertypesIterator s;
    s.listHead();
}

If I uncomment the specialization, I get the following errors:

$ g++ trouble.cc

trouble.cc: In constructor ‘supertypesIterator::supertypesIterator(Descriptor*)’:
trouble.cc:43:74: error: no matching function for call to ‘Tmpl<Descriptor, (selector)0u>::Tmpl(Descriptor*&)’
trouble.cc:43:74: note: candidates are:
trouble.cc:27:7: note: Tmpl<Descriptor, (selector)0u>::Tmpl()
trouble.cc:27:7: note:   candidate expects 0 arguments, 1 provided
trouble.cc:27:7: note: Tmpl<Descriptor, (selector)0u>::Tmpl(const Tmpl<Descriptor, (selector)0u>&)
trouble.cc:27:7: note:   no known conversion for argument 1 from ‘Descriptor*’ to ‘const Tmpl<Descriptor, (selector)0u>&’

What do I need to do to be able to initialize the base class from within the supertypesIterator ctor?

I’m using g++ version 4.7.1, though I’ll also need this to work cross-platform.

  • 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-08T23:52:11+00:00Added an answer on June 8, 2026 at 11:52 pm

    You have to implement the missing constructor in your specialization. Otherwise, the constructor for supertypesIterator is trying to call a constructor for Tmpl that doesn’t exist.

    template<selector s>
    class Tmpl<Descriptor, s> {
        Descriptor* root;
    public:
        Tmpl( Descriptor* t = 0 ) {
            root = t;
        }
        Descriptor listHead( ) {
            switch( s ){
                case supertype:
                    return Descriptor("Supertypes");
                case subtype:
                    return Descriptor("Subtypes");
            }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I inherit from a virtual template class, in this code: // test.h
I have a basic class that derived subclasses inherit from, it carries the basic
I want to use partial specialization for a template class so that all children
I'm using django 1.3 I'm using a base.html template which my pages inherit from.
I'm trying to inherit from a template class, using a type defined in the
Here is a minimal code that shows the problem: template<typename To, typename From> To
Goal : To inherit from a class with 2 template parameters. Error Error error
I'm trying to create a template wrapper class which inherits from its template parameter
Like a good little coder, all of my Django templates inherit from a base.html.
How to inherit from the windows explorer (Desktop, thing with help of which we

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.