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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:49:57+00:00 2026-05-23T03:49:57+00:00

struct B { void (B::*pf)(int, int); // data member B () : pf(&B::foo) {}

  • 0
struct B
{
  void (B::*pf)(int, int);  // data member
  B () : pf(&B::foo) {}
  void foo (int i, int j) { cout<<"foo(int, int)\n"; } // target method
};

int main ()
{
  B obj;
  // how to call foo() using obj.pf ?
}

In above test code, pf is a data member of B. What’s the grammar rule to invoke it ? It should be straight forward, but I am not getting a proper match. e.g. If I try obj.*pf(0,0); then I get:

error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘pf (...)’, e.g. ‘(... ->* pf) (...)’
  • 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-23T03:49:58+00:00Added an answer on May 23, 2026 at 3:49 am

    Like this:

    (obj.*obj.pf)(0, 1);
    

    Member access (.) has a higher precedence than a pointer to member operator so this is equivalent to:

    (obj.*(obj.pf))(0, 1);
    

    Because function call also has higher precedence than a pointer to member operator, you can’t do:

    obj.*obj.pf(0, 1) /* or */ obj.*(obj.pf)(0, 1)
    

    As that would be equivalent to:

    obj.*(obj.pf(0, 1)) // grammar expects obj.pf to be a callable returning a
                        // pointer to member
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void foo (int x) { struct A { static const int d = 0;
struct TimerEvent { event Event; timeval TimeOut; static void HandleTimer(int Fd, short Event, void
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
I'm so sick of the pass-callback-data-as-void*-struct anti-pattern. Boost bind solves it nicely, but is
The following code: template <typename S, typename T> struct foo { void bar(); };
typedef struct { nat id; char *data; } element_struct; typedef element_struct * element; void
Say I have a struct s with an int pointer member variable i. I
I've got class which is using plain-only-data struct with const variables and I'm not
struct a { int (*ptr1)(); int (*ptr2)(); int data; }; typedef struct { struct
that's the code: static inline void shrinkData(const vector<Data> &data, unsigned short shrinkType){ #define CASE_N(N)

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.