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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:05:42+00:00 2026-05-13T06:05:42+00:00

i have a nested struct and i’d like to have a pointer-to-member to one

  • 0

i have a nested struct and i’d like to have a pointer-to-member to one of the nested member:

is it legal?

struct InnerStruct
{
    bool c;
};
struct MyStruct {
    bool t;
    bool b;
    InnerStruct inner;
}; 

this:

MyStruct mystruct;
//...
bool MyStruct::* toto = &MyStruct::b;

is ok but:

bool MyStruct::* toto = &MyStruct::inner.c;

is not. any idea?

thanks

Here are some details
Yes it is &MyStruct::b and not mystruct::b;
The code is from a custom RTTI/Property system.
For each specified class we keep an array of “Property”, including a Ptr-to-member
It is used like this:

//somewhere else in code...
( myBaseClassWithCustomRTTIPointer)->* toto = true;
  • 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-05-13T06:05:43+00:00Added an answer on May 13, 2026 at 6:05 am

    Yes, it is forbidden. You are not the first to come up with this perfectly logical idea. In my opinion this is one of the obvious “bugs”/”omissions” in the specification of pointers-to-members in C++, but apparently the committee has no interest in developing the specification of pointers-to-members any further (as is the case with most of the “low-level” language features).

    Note that everything necessary to implement the feature in already there, in the language. A pointer to a-data-member-of-a-member is in no way different from a pointer to an immediate data member. The only thing that’s missing is the syntax to initialize such a pointer. However, the committee is apparently not interested in introducing such a syntax.

    From the pure formal logic point of view, this should have been allowed in C++

    struct Inner {
      int i;
      int j[10];
    };
    
    struct Outer {
      int i;
      int j[10];
      Inner inner;
    };
    
    Outer o;
    int Outer::*p;
    
    p = &Outer::i; // OK
    o.*p = 0; // sets `o.i` to 0
    
    p = &Outer::inner.i; // ERROR, but should have been supported
    o.*p = 0; // sets `o.inner.i` to 0
    
    p = &Outer::j[0]; // ERROR, but should have been supported
    o.*p = 0; // sets `o.j[0]` to 0
    // This could have been used to implement something akin to "array type decay" 
    // for member pointers
    
    p = &Outer::j[3]; // ERROR, but should have been supported
    o.*p = 0; // sets `o.j[3]` to 0
    
    p = &Outer::inner.j[5]; // ERROR, but should have been supported
    o.*p = 0; // sets `o.inner.j[5]` to 0
    

    A typical implementation of pointer-to-data-member is nothing more than just an byte-offset of the member from the beginning of the enclosing object. Since all members (immediate and members of members) are ultimately laid out sequentially in memory, members of members can also be identified by a specific offset value. This is what I mean when I say that the inner workings of this feature are already fully implemented, all that is needed is the initialization syntax.

    In C language this functionality is emulated by explicit offsets obtained through the standard offsetof macro. And in C I can obtain offsetof(Outer, inner.i) and offsetof(Outer, j[2]). Unfortunately, this capability is not reflected in C++ pointers-to-data-members.

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

Sidebar

Related Questions

I have nested routes like this : map.resources :foo do |foo| foo.resources :bar do
I keep finding that if I have nested divs inside each other, and one
I have the following code: class outer { struct inner { int var1; int
I have a std::vector that holds a Point struct (x,y,z and some other non-pointer
Suppose we have to use in some function deeply nested pointer very extensively: function
I have nested dictionaries: {'key0': {'attrs': {'entity': 'p', 'hash': '34nj3h43b4n3', 'id': '4130'}, u'key1': {'attrs':
I have nested xsl:for loops: <xsl:for-each select=/Root/A> <xsl:for-each select=/Root/B> <!-- Code --> </xsl:for> </xsl:for>
as per the title; is it possible to have nested comments in valid HTML?
I have some nested tables that I want to hide/show upon a click on
I have a nested function to show/hide paragraphs news-ticker-style. The problem is that when

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.