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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:25:17+00:00 2026-06-08T10:25:17+00:00

Here is the code: template <typename T> struct Outer { struct InnerBase { int

  • 0

Here is the code:

template <typename T>
struct Outer {
  struct InnerBase {
    int n;
    InnerBase() : n(42) { }
  };
  struct InnerChild : InnerBase {
    int getN() { return n; }
  };
};

And here is the problem:

In member function 'int Outer<T>::InnerChild::getN()':
error: 'n' was not declared in this scope

If the Outer is not a template, everything works fine. How so? How to fix it in the template?

  • 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-08T10:25:18+00:00Added an answer on June 8, 2026 at 10:25 am

    InnerBase is not a free-standing type, but actually a dependent class, since it is really Outer<T>::InnerBase. Thus InnerChild doesn’t know from whom exactly it is inheriting (think of specializations*!), and thus it cannot know that n is actually a name.

    To assert that n is indeed a name of a class member, say this->n or InnerBase::n, or add a declaration using InnerBase::n; at some point in InnerChild.

    *) e.g. template <> struct Outer<int>::InnerBase { typedef int n; };

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

Sidebar

Related Questions

Here is the code for templates specilization: template <int i> struct userInput{}; template <>
See,I have this code: template<typename T=int>struct color { T red, green, blue; color(T r,
Here is a minimal code that shows the problem: template<typename To, typename From> To
Here is the code I was looking, Source code : template <typename T> struct
Here is the code that works fine : template<typename... Args> struct count; template<> struct
Here is my somewhat odd code: template <typename T&> class A { public: void
Here's some code (full program follows later in the question): template <typename T> T
please consider the following code: template <typename T> struct foo { template <typename S>
Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream
I'd like to be able to do this: template<typename Mix> struct A { A(int

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.