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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:55:51+00:00 2026-06-07T19:55:51+00:00

When using the pointer to member operator (->*), what pointer values for the object

  • 0

When using the pointer to member operator (->*), what pointer values for the object will invoke undefined behavior?

Specifically, if the member function in question does not access any members and is not virtual are either of the following bad?

  • Null pointers
  • Pointers to objects which have already been deleted

This question is similar but discusses regular member function calls.

To illustrate with code:

#include <iostream>     
using namespace std;     

class Foo {     
public:     
  int member(int a)     
  {     
    return a+1;     
  }     
};     

typedef int (Foo::*FooMemFn)(int);     

int main(int argc, char** argv)     
{     
  FooMemFn funcPtr = &Foo::member;     
  Foo *fStar = 0;     
  Foo *fStar2 = new Foo();     
  delete fStar2;     

  int a1 = (fStar->*funcPtr)(4);  //does this invoke UB?                                                                                                                                                                                                                             
  int a2 = (fStar2->*funcPtr)(5); //what about this?                                                                                                                                                                                                                               

  cout<<"a1: "<<a1<<"  a2: "<<a2<<endl;     

  return 0;     
}

Questions about undefined behavior are questions about the C++ standard, so I am looking for specific references to sections of the C++ standard.

  • 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-07T19:55:53+00:00Added an answer on June 7, 2026 at 7:55 pm
    int a1 = (fStar->*funcPtr)(4);  //does this invoke UB?  
    int a2 = (fStar2->*funcPtr)(5); //what about this? 
    

    Yes. Both statements invoke UB.
    Because they are equivalent to:

    fStar->member(4);
    fStar2->member(5);
    

    respectively.

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

Sidebar

Related Questions

Possible Duplicate: Pointers in java Why java is not using pointer though C# and
I have a problem with using a pointer to function in C++. Here is
I am trying to fire an event from a unmanaged function using a pointer
I read that an overloaded operator declared as member function is asymmetric because it
Template compilation error using pointer of pointer: (What causes the code not to compile
If I define a pointer to an object that defines the [] operator, is
How to print a particular member of a structure using pointer arithmetic? I have
In my int Queue::remove(int x) member function of my Queue class that you will
I want to eliminate the process consumed by a decision using pointers to member
Using pointer arithmetic, it's possible to assign characters from one array to another. My

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.