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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:24:30+00:00 2026-06-04T04:24:30+00:00

In the following setup, how can I make it so that I can refer

  • 0

In the following setup, how can I make it so that I can refer to the name Bar inside the derived class Derived<T>?

template <typename T> struct Foo
{
    template <typename U> struct Bar { };
};

template <typename T> struct Derived : Foo<T>
{
    // what goes here?

    Bar<int> x;  // Error: 'Bar' does not name a type
};

I’ve tried using Foo<T>::Bar;, but that doesn’t help. Is there any sort of using declaration that can make the name of a nested base template known to the derived class, so that I can keep the simple de­cla­ration Bar<int> x?

I know that I can say typename Foo<T>::template Bar<int> x;, but I have a lot of those cases and I don’t want to burden the code needlessly with so much verbosity. I also have a lot of distinct “ints”, so a typedef for each nested-template instance is not feasible, either.

Also, I cannot use GCC 4.7 at this point nor C++11, and would thus like a “traditional” solution without template aliases.

  • 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-04T04:24:31+00:00Added an answer on June 4, 2026 at 4:24 am

    In C++11 you can use an alias template:

    template <typename T> struct Derived : Foo<T>
    {
      template<typename X> using Bar = typename Foo<T>::template Bar<X>;
      Bar<int> x;
    };
    

    Edit

    The traditional solution is what you’re already said, typename Foo<T>:template Bar<int>, or to emulate a “template typedef”

    template <typename T> struct Derived : Foo<T>
    {
      template<typename X>
        struct Bar
        { typedef typename Foo<T>::template Bar<X> type; };
      typename Bar<int>::type x;
    };
    

    One of the reasons for adding alias templates to the language is they support things which can’t be expressed easily in C++03.

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

Sidebar

Related Questions

I'd like to have the following setup: class Descriptor { public string Name {
I have the following admin setup so that I can add/edit a user and
The Current Setup: So, I can use the following code to save a file
I have this following setup, a textarea named with some data in it that
I'm new to git, and I can't make sense of the following behavior: I
I am attempting to install libxml2 so that I can setup the python bindings
I can't make py2exe to pack correctly even a simple script that uses win32file
In the following example, can I use build() instead of create() ? class UsersControllerTest
I have the following setup, and I need to know how to persist state.
I'm using the following setup: public MySQLProcessWriter(Connection con) throws SQLException { String returnNames[] =

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.