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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:33:38+00:00 2026-06-11T15:33:38+00:00

I have a child class (Child) that inherits a base class (Base) templated on

  • 0

I have a child class (Child) that inherits a base class (Base) templated on the child class. The child class is also template on a type (can be integer or whatever …), and I’m trying to access this type in the base class, I tryed a lot of stuff without success … here is what I think might be the closer to a working solution, but it doesn’t compile …

template<typename ChildClass>
class Base
{
    public: 
        typedef typename ChildClass::OtherType Type;

    protected:
        Type test;
};

template<typename TmplOtherType>
class Child
    : public Base<Child<TmplOtherType> >
{
    public:
        typedef TmplOtherType OtherType;
};

int main()
{
    Child<int> ci;
}

here is what gcc tells me:

test.cpp: In instantiation of ‘Base >’: test.cpp:14:7:
instantiated from ‘Child’ test.cpp:23:16: instantiated from
here test.cpp:7:48: error: no type named ‘OtherType’ in ‘class
Child’

Here is a working solution that is equivalent :

template<typename ChildClass, typename ChildType>
class Base
{
    public:
        typedef ChildType Type;

    protected:
        Type test;
};

template<typename TmplOtherType>
class Child 
    : public Base<Child<TmplOtherType>, TmplOtherType>
{
    public:
};

But what bothers me is the repetitive template parameter (forwarding the TmplOtherType as Childtype) to the base class …

What do you guys think ?

  • 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-11T15:33:40+00:00Added an answer on June 11, 2026 at 3:33 pm

    You could use template template parameter to avoid repetitive template arguments:

    template<template<typename>class ChildTemplate, //notice the difference here
              typename ChildType>
    class Base
    {
      typedef ChildTemplate<ChildType>  ChildClass; //instantiate the template
      public:
        typedef ChildType Type;
    
      protected:
        Type test;
    };
    
    template<typename TmplOtherType>
    class Child 
        : public Base<Child, TmplOtherType> //notice the difference here also
    {
        public:
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Base class and a Child class that inherits from Base
I have a base class that is a Django form. The child class then
In Javascript I have a child object that inherits from a base object. I
I have a base class line which has a child class arc (note that
I have base class that is called Entity. Then I have two child class
I have a base class that three classes inherit from. Whenever these child classes
I have a base class with a templated function that has the general templated
I have a class that inherits from a base class. This base class exposes
In Django, when you have a parent class and multiple child classes that inherit
I have a parent and child class that both need to implement IDisposable .

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.