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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:29:37+00:00 2026-05-31T05:29:37+00:00

Possible Duplicate: C++ member-function pointer How to invoke pointer to member function when it's

  • 0

Possible Duplicate:
C++ member-function pointer
How to invoke pointer to member function when it's a class data member?

I’ve only recently started using C++, so I apologize if the following contains any trivial mistakes, or if I missed an easier solution. I would like to achieve something like this:

class ClassA {

typedef double (ClassA::*CondFunc)();
 public:
    ClassA(int x, int y) {

        value_ = x;

        switch (y) {
            case 0:
                condFunc_ = &ClassA::condA;
                break;
            case 1:
                condFunc_ = &ClassA::condB;
            default:
                break;
        }
    }

    ~ClassA();

    int value_;
    CondFunc condFunc_;
    double condA() { return 2.0*value_; }
    double condB() { return 4.0*value_; }

    void Test() {
        int a = condFunc_(); // compile error
    } 
};

but get a compile error in Test(). Please note that this is a vastly simplified function and is not supposed to make any sense. I’ve searched this forum and elsewhere for answers, but am still not sure whether defining/calling such non-static member function pointers is even possible. The only plausible hint/solution I’ve come across employs a static wrapper function to achieve something similar. I’d be grateful for any help/clarifications.

  • 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-31T05:29:38+00:00Added an answer on May 31, 2026 at 5:29 am

    You have to call the member pointer function like this:

        int a = (this->*condFunc_)(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Templates: template function not playing well with class’s template member function template
Possible Duplicate: problem sorting using member function as comparator Is it possible to use
Possible Duplicate: C++ invoke explicit template constructor First imagine I have a class Data
Possible Duplicate: Virtual Functions and Performance C++ Is this correct, that class member function
Possible Duplicate: c++ publicly inherited class member cannot be used as default argument Nonstatic
Possible Duplicate: What will happen when I call a member function on a NULL
Possible Duplicate: How to get the address of an overloaded member function? I have
Possible Duplicate: When does invoking a member function on a null instance result in
Possible Duplicate: When does invoking a member function on a null instance result in
Possible Duplicate: Does a const reference class member prolong the life of a temporary?

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.