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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:41:17+00:00 2026-05-17T15:41:17+00:00

Take this code: struct mystruct { int var; mystruct() : var(0) {} }; int

  • 0

Take this code:

struct mystruct
{
    int var;

    mystruct() : var(0) {}
};

int main()
{
    mystruct ins;

    int* p = &ins.var;

    *p = 1;
}

So what are some concrete really good examples of uses for the class member pointer?

int    X::*p = &X::data; /* p contains offset */
X      object;
X      *objptr = new X;

int    i = object.*p;
int    j = objptr->*p;
  • 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-17T15:41:18+00:00Added an answer on May 17, 2026 at 3:41 pm

    It seems the your question is about pointers of pointer-to-data-member type. In C++ there are also pointers of pointer-to-member-function type. The two have something in common at some abstract level, but otherwise they are different.

    Pointer of pointer-to-data-member type is applicable to any instance of the class. An ordinary pointer always points to a member of a specific instance of the class. Pointer of pointer-to-data-member type is a higher level implementation of the idea of “run-time offset” from the beginning of a class object. It is a relative pointer. In that way it is completely different thing from ordinary pointers, which are absolute pointers.

    To illustrate that with an example, let’s say you have an array of classes with three members of the same type x, y and z

    struct Point { int x, y, z; };
    
    Point point_array[N];
    

    and you need to set all members with the same name to 0 in the entire array, without changing any other members. Here’s how you can do it using a pointer of pointer-to-data-member type

    void zero_members(Point points[], int n, int Point::*m) {
      for (int i = 0; i < n; ++i)
        points[i].*m = 0;
    }
    

    Now, by using this function you can do

    zero_members(point_array, N, &Point::x);
    

    to set all xs to zero. Or you can do

    zero_members(point_array, N, &Point::y);
    

    to set all ys to zero. You do can all this with a single function, and what’s also important, the member selection is performed by a run-time parameter (as opposed to a compile-time one).

    You cannot do something like this with ordinary pointers. In fact, you can’t do it in any other way.

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

Sidebar

Related Questions

Take a look at this code: public class Test { public static void main(String...
I have 3 sets in Linq, like this: struct Index { string code; int
Consider this code: template <int N> struct X { friend void f(X *) {}
Take this code into consideration: Proxy p = new Proxy(Type.SOCKS, new InetSocketAddress(proxyURL, port)); try
Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
Take this code: $json = file_get_contents($this->url, true); $decode = json_decode($json, true); foreach ($decode as
Take this example code (ignore it being horribly inefficient for the moment) let listToString
take this simple code: class A{ public: virtual void foo() = 0; void x(){
take a look at this code: $(document).ready(function() { document.getElementById(sliderId).onmousedown = sliderMouseDown; }); function sliderMouseDown()
Take a look on this code, what I wrote: http://pastebin.com/TZpUAWpA , and this jQuery,

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.