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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:20:24+00:00 2026-05-23T01:20:24+00:00

I need to map some state to a particular member function of a class,

  • 0

I need to map some state to a particular member function of a class, for (a very cut down) example:

class Z {
   _a_ptr_to_some_member _p;

   void UpdateGuiForStopState(State s) {
      // do something with state
   }

   Z() {
      // setup _p to point to UpdateGuiForStopState
   }

   void StateComesInHere(State s) {
      if(s.id == STOP_ID) { // eventually use lookup
         _p(s);
      }
   }
}

Using just the STL (can’t use third party stuff like boost), What is the type of _a_ptr_to_some_member and how do I bind the method UpdateGuiForStopState to it?

Presumably I use the stl mem_xxx stuff but can’t work out how.

And yes I can do this a hundred and one other different ways, but I want to work out if this way is possible.

  • 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-23T01:20:25+00:00Added an answer on May 23, 2026 at 1:20 am

    Using STL’s bind1st and mem_fun:

    class Z3 {
       typedef std::mem_fun1_t<void,Z3,State> _a_ptr_to_some_member_raw;
       typedef std::binder1st<_a_ptr_to_some_member_raw> _a_ptr_to_some_member;
       _a_ptr_to_some_member _p;
    
       void UpdateGuiForStopState(State s) {
          // do something with state
       }
    
       Z3() : _p(std::bind1st(std::mem_fun(&Z3::UpdateGuiForStopState), this))
       {
       }
    
       void StateComesInHere(State s) {
          if(s.id == STOP_ID) { // eventually use lookup
             _p(s);
          }
       }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use C++ stdlib map whenever I need to store some data associated
I need to map a class which has a list of Enums to a
I need a function which works like: some :: (Int, Maybe Int) -> Int
I have a map declared inside a class as follows: class Example { public:
I am writing some map commands that run external commands. For example, I may
I need to represent the state of some devices from the db on the
I have some service which does some file processing. It may need to map
I need to map most of the computer memory as uswc to take advantage
I'm using python and I need to map locations like Bloomington, IN to GPS
In php, I often need to map a variable using an array ... but

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.