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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:55:09+00:00 2026-05-30T13:55:09+00:00

I have a rather unusual problem… we are tasked with mapping a series of

  • 0

I have a rather unusual problem… we are tasked with mapping a series of hexadecimal values to function pointers. However, I want to be able to call the function with already predefined parameters. Here is a segment of code that I am trying to get to work:

map<short, void(*)(MyClass, MyClass)> mapping = create_map();


map<short, void(*)(MyClass, MyClass)> create_map()
{
    map<short, void(*)(MyClass, MyClass)>> m;
    m[1] = &function(new MyClass(), new MyClass());
    return m;
}

However, it will only let me put function without parameters into the mapping. How do I store this setup and call it later?

  • 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-30T13:55:11+00:00Added an answer on May 30, 2026 at 1:55 pm

    If you are using C++11, You can use std::bind:

    void function(MyClass* a, MyClass* b) { ... }
    
    typedef map<short, std::function<void()>> funcmap;
    
    funcmap create_map()
    {
        funcmap m;
        m[1] = std::bind(function, new MyClass, new MyClass);
        return m;
    }
    
    // use:
    
    funcmap mapping = create_map();
    mapping[1]();
    

    If not, you can create a struct that stores the arguments and the function pointer. Then write an operator() which will call the function through the function pointer with the arguments it stored:

    struct func {
        typedef void(*fptr)(MyClass*, MyClass*);
    
        func(fptr f, MyClass* m1, MyClass* m2) : ptr(f), arg1(m1), arg2(m2) { }
    
        void operator()() {
            ptr(arg1, arg2);
        }
    
        T ptr;
        MyClass* arg1, arg2;
    };
    
    void function(MyClass* a, MyClass* b) { ... }
    
    typedef map<short, func> funcmap;
    
    funcmap create_map()
    {
        funcmap m;
        m[1] = func(function, new MyClass, new MyClass);
        return m;
    }
    
    // use:
    
    map<short, func> mapping = create_map();
    mapping[1]();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather unusual problem, and it is hurting my brain. Problem: Given
I have a rather unusual idea. I want to run a single instance of
I have a rather complex decorator written by someone else. What I want to
I have a rather annoying problem. I have a table view with blog entries
I have some rather dodgy data I'm looking at, and I've been tasked with
A rather unusual situation perhaps, but I want to specify a private SSH-key to
I have a rather unusual layout that I'm trying to make a reality. There
I am faced with rather unusual situation I will have url in any of
I have a rather weird problem deploying my application ... I compile the application
This is a rather unusual question but here's the issue: I have a WPF

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.