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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:58:32+00:00 2026-06-17T13:58:32+00:00

Hey so I am making a map with string as the key and a

  • 0

Hey so I am making a map with string as the key and a member function pointer as the value. I can’t seem to figure out how to add to the map, this doesn’t seem to be working.

#include <iostream>
#include <map>
using namespace std;

typedef string(Test::*myFunc)(string);
typedef map<string, myFunc> MyMap;


class Test
{
private:
    MyMap myMap;

public:
    Test(void);
    string TestFunc(string input);
};





#include "Test.h"

Test::Test(void)
{
    myMap.insert("test", &TestFunc);
    myMap["test"] = &TestFunc;
}

string Test::TestFunc(string input)
{
}
  • 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-17T13:58:33+00:00Added an answer on June 17, 2026 at 1:58 pm

    See std::map::insert and std::map for value_type

    myMap.insert(std::map<std::string, myFunc>::value_type("test", &Test::TestFunc));
    

    and for operator[]

    myMap["test"] = &Test::TestFunc;
    

    You cannot use a pointer to member function without an object. You can use the pointer to member function with an object of type Test

    Test t;
    myFunc f = myMap["test"];
    std::string s = (t.*f)("Hello, world!");
    

    or with a pointer to type Test

    Test *p = new Test();
    myFunc f = myMap["test"];
    std::string s = (p->*f)("Hello, world!");
    

    See also C++ FAQ – Pointers to member functions

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

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
Hey, I am making an AI on ROBLOX and I can't seem to figure
Hey I can't figure out what the equation to find the new angle of
Hey so I'm making a serialization function that takes a base class pointer 'Joint'
Hey Guys, Ok so I have been trying to figure this out for the
Hey, so I'm making an iPhone app and in there is a common function
Hey im making a website were you can send other users emails. My problem
Hey out there in Stackland. I'm making a very javascript-heavy site, and at a
Hey im making a planeManagerApp. I have a TreeMap containing Airline , HashMap(String,Plane); I
Hey so i'm making a function that gathers up sprites that you wanna keep

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.