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 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 this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
For instance, take this piece of code: var person = new Person(); or for
The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
take a look at this example code: public class Comment { private Comment() {
This one will take some explaining. What I've done is create a specific custom
Compiling this lines long int sz; char tmpret[128]; //take substring of c, translate in
What I'm trying to do is take this code: char naive_smooth_descr[] = naive_smooth: Naive
Possible Duplicate: Is it safe for structs to implement interfaces? Take this code: interface
Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: string

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.