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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:48:06+00:00 2026-06-04T05:48:06+00:00

I have a function that requires a function pointer as argument: int func(int a,

  • 0

I have a function that requires a function pointer as argument:

int func(int a, int (*b)(int, int))
{
    return b(a,1);
}

Now I want to use a certain function that has three arguments in this function:

int c(int, int, int)
{
    // ...
}

How can I bind the first argument of c so that I’m able to do:

int i = func(10, c_bound);

I’ve been looking at std::bind1st but I cannot seem to figure it out. It doesn’t return a function pointer right? I have full freedom to adapt func so any changes of approach are possible. Althoug I would like for the user of my code to be able to define their own c…

note that the above is a ferocious simplification of the actual functions I’m using.

The project sadly requires C++98.

  • 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-04T05:48:08+00:00Added an answer on June 4, 2026 at 5:48 am

    You can’t do that. You would have to modify func to take a function-object first. Something like:

    int func( int a, std::function< int(int, int) > b )
    {
        return b( a, rand() );
    }
    

    In fact, there is no need for b to be an std::function, it could be templated instead:

    template< typename T >
    int func( int a, T b )
    {
        return b( a, rand() );
    }
    

    but I would stick with the std::function version for clarity and somewhat less convoluted compiler output on errors.

    Then you would be able to do something like:

    int i = func( 10, std::bind( &c, _1, _2, some-value ) );
    

    Note all this is C++11, but you can do it in C++03 using Boost.

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

Sidebar

Related Questions

I have a PHP function that requires can take 3 parameteres... I want to
I have a C++ class that requires a function pointer in it's constructor (
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that
I have a function that is recursively calling itself, and i want to detect
Please suppose I have a function that accepts a pointer as a parameter. This
In C++ I have a function that only requires read-only access to an array
Some functions have a pointer argument that points to where a result from calling
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick

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.