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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:32:34+00:00 2026-06-14T07:32:34+00:00

If I use a chain of inheritance like the following example I could use

  • 0

If I use a chain of inheritance like the following example I could use vars from the deepest base without any problems:

    class A { public: int x; };
    class B : public A { };
    class C: public B { public: void Do() { cout << x << endl; } };

If I do the same with recursive variadic template classes I could not access my vars. Any idea how to access the vars and why I could not see my vars?

    template <class ...Parms>
    class Example;

    template <class Head, class ...Parms>
    class Example<Head, Parms...>: public Example<Parms...>
    {
    };

    template <>
    class Example<>
    {
        public:
        int x;
    };

    template <class ...Parms>
    class Last: public Example<Parms...>
    {
        void Do() { cout << x << endl; }
    };

Compile fails before any instance of the class is instantiated!

  • 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-14T07:32:35+00:00Added an answer on June 14, 2026 at 7:32 am

    x is a dependent name in this case, so you must access if as this->x (or bring it into scope by putting a using declaration in your class definition:

    using Example<Params...>::x;
    

    EDIT

    The reason for this is discussed in [temp.res] in the standard. Basically: when the compiler is parsing your template, it sees just x. It has no way of knowing that x depends on the template’s parameters (which it does in your case, because it comes from a base class which depends on them). Therefore, the compiler tries to resolve x using what it knows when parsing the template, and fails.

    Writing this->x indicates that x refers to a member of the class; since a base class of your particular class depends on template parameters, the compiler knows it cannot resolve x when parsing the template, and will postpone the resolution until the template is instantiated. At that time, the template arguments are known.

    The same holds true for using Example<Params...>::x;. That also tells the compiler that x depends on template parameters, and its resolution must be postponed to instanitation.

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

Sidebar

Related Questions

I would like to use itertools.chain for efficient concatenation of lists (memoization), but I
I've got an inheritance chain of three classes: Baz inherits from Bar inherits from
The typical way of implementing IUnknown::QueryInterface() is the following: use a chain of if-else-if
Suppose I have an inheritance chain where every class extends its superclass by adding
I'd appreciate any advice on which way to go on in the following scenario.
I'm defining several classes intended to be used for multiple inheritance, e.g.: class A:
I often use grep and sed in my bash scripts. For example, I use
I'm trying to write a SSL-based async server using Boost ASIO example code from
In answer to this question I tried to use Type.GetCustomAttributes(true) on a class which
I have two abstract classes in an inheritance chain, within what will eventually be

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.