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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:25+00:00 2026-06-09T03:10:25+00:00

This is what I want to achieve. The leaf component will inherit Component<ParentT> ,

  • 0

This is what I want to achieve. The leaf component will inherit Component<ParentT>, others will inherit Component<ParentT, ChildT>

template <typename T>
class Component{
  protected:
    typedef Component<T> ParentComponentT;
  ...
};

template <typename ParentT, typename ChildT>
class Component: public Component<ParentT>{
  protected:
    typedef std::vector<ChildT*> CollectionT;
  ...
};

But the problem is Template parameters getting redeclared. and I cannot move the second one above first one because second one inherits first one.

error: redeclared with 2 template parameter(s)
note: previous declaration ‘template class Component’ used 1 template parameter(s)

  • 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-09T03:10:30+00:00Added an answer on June 9, 2026 at 3:10 am

    This compiles and as far as I understand does what you like:

    #include <vector>
    
    class NoneT {};
    
    template <typename ParentT,typename ChildT=NoneT>
    class Component: public Component<ParentT>{
      protected:
        typedef std::vector<ChildT*> CollectionT;
    };
    

    Specialization for NoneT:

    template<>
    template<typename T>
    class Component<T,NoneT>{
    protected:
       typedef Component<T> ParentComponentT;
    };
    
    int main(){
       typedef Component<double> someT;
       typedef Component<double,int> someT2;
       typedef Component<double,void> someT3;
    }
    

    someT will have ParentComponentT and someT2 will have CollectionT.

    EDIT:

    Answer to comment/question below: typename ChildT=noneT means that the default ChildT will be noneT. So, if no second template argument is given the noneT type will be used.

    The specialization then defines the class content for the that one-argument version.

    EDIT2:

    Since I know from the chat that you use Component as a base class, I suggest that instead of something like

    class myclass: public Component<Section, Line>
    

    you could use multiple inheritance

    class myclass: public ParentComponent<Section>, CollectionComponent<Line>
    

    with

    template <typename T>
    class ParentComponent{
      protected:
        typedef Component<T> ParentComponentT;
    };
    
    template <typename ChildT>
    class CollectionComponent {
      protected:
        typedef std::vector<ChildT*> CollectionT;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I want to achieve is this: Declare a generic class (<T>), Have the
I have ItemsControl with DataTemplate that looks like this: I want to achieve effect
I want to achieve this effect: When the user focus a text area within
I want to achieve this using html and css: I have tried to set
I want to achieve this: private static InputStream getTokenCfg() { String cfg = MessageFormat.format(
I want to achieve a list like this with smarty. <ul> <li> <a>img1</a> <a>img2</a>
I want to achieve something like this in C# 3.5: public void Register<T>() :
I want to achieve something like this inside a UIView: I have created a
I want to achieve the functionality that this editor has got with its preview
This is what I want to achieve. [Item 0] [Item 1] [Item 2] [Item

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.