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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:57:32+00:00 2026-06-18T14:57:32+00:00

The next code works fine (this is a oversimplified version of other problem of

  • 0

The next code works fine (this is a oversimplified version of other problem of mine, with types longer, deeper and more templates):

template<class C>
struct Base
{};

template<class C>
struct Derived : public Base<C>
{
   Derived() : Base<C>()
   {}
};

But, how could I call to the base class constructor without “write” the complete type of its base class? For example, I tried something like:

template<class C>
struct Base
{
   typedef Base base_type;
};

template<class C>
struct Derived : public Base<C>
{
   Derived() : base_type() {}
};

int main()
{
   Derived<void> b;
}

But “base_type” isn’t recognized. The message that gcc throws is:

test3.cpp: In constructor 'Derived<C>::Derived()':
  test3.cpp:100:17: error: class 'Derived<C>' does not have any field
  named 'base_type'

To solve it I have to write Base<C>::base_type in the constructor but this would make the existence of base_type itself irrelevant.

Is it my campaign of writting-saving impossible?

And, why base_type in the constructor isn’t found, and however this works fine?

int main()
{
   Derived<void>::base_type b;
}

EDIT: With the comment of @Jack Aidley the best form I’ve found to get the type of the base class with a simple alias is:

template<typename C> struct Base {};

template<typename C, typename Base>
struct Derived_impl : public Base
{
    Derived_impl() : Base()
    {}
};

template<typename C>
using Derived = Derived_impl<C, Base<C> >;

int main()
{
   Derived<void> b;
}
  • 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-18T14:57:33+00:00Added an answer on June 18, 2026 at 2:57 pm

    According to the standard

    When looking for the declaration of a name used in a template
    definition, the usual lookup rules (3.4.1, 3.4.2) are used for
    nondependent names. The lookup of names dependent on the template
    parameters is postponed until the actual template argument is known
    (14.6.2).

    It means, that you have to tell to the compiler, that base_type in the Base class, that depends of C. You can use, for example, this:

    template<class C>
    struct Derived : public Base<C>
    {
        using typename Base<C>::base_type;
    
        Derived() : base_type() {}
    };
    

    or this

    template<class C>
    struct Derived : public Base<C>
    {
        Derived() : Derived<C>::base_type() {} 
    
        // or, as you already told, Base<C>::base_type()
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've the next problem: The code to validate the name, address and email works,
This code works fine in SQL 2005 but appears to miss a random number
my code works fine but I am getting this exception a lot and it's
This code works fine to create a grid of divs: for (var i =
Locally everything works fine, but on a remote Weblogic not really. The next code
Me again. This code works fine when only 1 item is selected, however when
The following code works fine: typedef struct node_s { void *data; struct node_s *next;
Painting some particles stored in an ArrayList. This code works fine: super.paintComponent(g); for (Particle
This code is works fine when you type 22 and 56 for example, it
How does this code work to Find the next highest power of 2 for

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.