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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:35:02+00:00 2026-06-13T05:35:02+00:00

How to access non-static class member? class A { int value_ = 0;//I want

  • 0

How to access non-static class member?

class A
{
    int value_ = 0;//I want to access this member in class inheriting from A
};
template<class X = A>
class Y :X
{
static_assert(value_ == 0,"Non-zero not allowed");//here I want to access value_ from X which is A by default. Is this possible?
};
  • 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-13T05:35:04+00:00Added an answer on June 13, 2026 at 5:35 am

    What you are specifically doing is not possible, for several reasons.

    First, static_assert requires it’s argument to be a compile-time constant expression. value_ is most assuredly not.

    You could try to make it a constant expression by labeling it constexpr. But C++11 doesn’t allow constexpr for non-static data members. And even if it did, that’s not going to help because value_ is a non-static member. As such, it doesn’t exist yet. It only exists when there is an actual class instance, something that has a this pointer. Your static_assert expression doesn’t create one of those objects, so there’s no way to access it.

    Therefore, in order to make this “work” (to the extent that “working” does something meaningful), you must:

    1. Give A a constexpr constructor, so that you can create a constexpr instantiation of it.
    2. Your static_assert must actually create a type using the constexpr constructor and access the data member in question.

    Now, if you do this, you’re going to find that it doesn’t give you what you want (based on this statement, since your question didn’t explain what exactly it is you’re trying to accomplish):

    Secondly, by every time I meant every time object of this class is created, and as a X is a template param it is a constant expression.

    Note that static_assert is static. Whereas “every time object of this class is created” is a runtime event. You cannot perform a static test on something that happens at runtime.

    What you want is regular assert, not static_assert.

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

Sidebar

Related Questions

Access static method from non static class with object. It is not possible in
I have a project having a static and non-static class. I want to access
I have a small template class with a non-static member of type boost::shared_mutex .
When I try to access the Host object from a non-static method declared in
I would like to access the data within this member function that is static.
I want that when a non logged in user tries to access any controller
Access modifiers like public , private are not allowed on static constructors in C#.
I have a class, in which i declare a static function. I register this
I have a query regarding accessibility of top level class from member inner class.
I have two questions. In C++, a static member function has direct access to

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.