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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:26:58+00:00 2026-06-12T07:26:58+00:00

Let’s say I have two functions: void a(int arg1) { … } void b(int

  • 0

Let’s say I have two functions:

void a(int arg1) { ... }
void b(int arg1, arg2) { ... }

And I also have a string with the name of the function I want to call, and an array with all parameters:

string func_name = "b"; // 'a' or 'b'
int args[] = { 1, 2 }; // has either 1 or 2 values

I need to call the function dynamically. Doing it with a function that has no arguments is really easy, I just created a map (string function_name => pointer to function).

Now I also want to pass the arguments, so I want to convert an array to actual arguments, something like this:

auto f = std::bind(b, args); // Doesn't compile, requires 1,2 as arguments

I hope the problem is clear and that it is solvable.

Thanks

  • 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-12T07:27:00+00:00Added an answer on June 12, 2026 at 7:27 am

    Inspired by this answer https://stackoverflow.com/a/1287060/942596 you can achieve what you want using macro’s

    #define BUILD0(x) x[0]
    #define BUILD1(x) BUILD0(x), x[1]
    #define BUILD2(x) BUILD1(x), x[2]
    #define BUILD3(x) BUILD2(x), x[3]
    #define BUILD(x, i) BUILD##i(x)
    
    
    void foo(int i) {std::cout << i << std::endl;}
    void foo(int i, int j) {std::cout << j << std::endl;}
    void foo(int i, int j, int k) {std::cout << k << std::endl;}
    void foo(int i, int j, int k, int l) {std::cout << l << std::endl;}
    
    int main() {
        int x[] = {1, 2, 3};
        boost::bind(foo, BUILD(x, 2))();
    }
    

    Node: this does not account for this situation of 0 parameters.

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

Sidebar

Related Questions

Let's say I have 2 functions: void function1(int *ptr) { printf(%d, *ptr); } and
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have window.open (without name parameter), scattered in my project and I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012

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.