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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:20:27+00:00 2026-06-02T23:20:27+00:00

My problem is following, I have a function which takes one function as a

  • 0

My problem is following, I have a function which takes one function as a parameter. The problem is that in some cases the passed function fEval() needs to be called with two parameters instead of one as fEval(somevalue1,somevalue2)

Func(double (*fEval)(double F1),double min, double max,...)
{
    double value1 = fEval(10);

    // do something here

    double value2 = fEval(20,30);
}

So what would be the correct way to implement Func function ?
I know I can’t do it either

Func(double (*fEval)(double F1),double min, double max,...)

or

Func(double (*fEval)(double F1,double F2),double min, double max,...)

Thanks !

Okay let me rephrase the problem. I need to create a function which could take a one unknown function as a first parameter, two different values and an argument list.
Something like

double Function(RandomFunction, val1, val2, ...);

The random function will be either:

double Func1(double x)
{
    m_x = x;
    //Calling function
    // Set other things
}
double Func2(double x,double y)
{
    m_y = y;
    m_x = x;
    //Calling function
    // Set other things
}

I’ll try that functor way but I’m not sure is it right way to do this ? Doesn’t it require me to overload () inside of the possible functions what could be called ?

  • 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-02T23:20:28+00:00Added an answer on June 2, 2026 at 11:20 pm

    You probably should require a functor that has operator() overloaded to take one or two arguments:

    struct Functor {
        double operator()(double d) {
            ....
        }
    
        double operator()(double d1, double d2) {
            .... 
        }
    };
    
    void Func(Functor f, double min, double max, ...) {
        double value1 = f(10);
    
        // do something here
    
        double value2 = f(20, 30);
    }
    

    Other than that (besides passing around variadic functions, which wouldn’t be good because it couldn’t know whether it was being called with one or two arguments) I don’t think there is another good way to have a function that can take both 1 or 2 arguments.

    And as ildjarn mentioned in the comments, you could also make it a template so it can take any kind of functor:

    template<typename Functor_t>
    void Func(Functor_t f, double min, double max, ...) {
        // same as above
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems with following code: http://lisper.ru/apps/format/96 The problem is in normalize function, which
I have the following function. The problem is that the $lang variable will vary
I have the following loop which is giving me problems $(#divResults).append('<table>'); $.each( results.d, function(
The problem is the following. We have lots of ajax call via $.ajax function.
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have a function which must return one dimensional associate array, like $user_info[$index]=value where
I have the following plugin, which takes a partial game name, bounces it off
I have been looking for a design that solves the following problem. It will
I've been struggling with the following problem. I have a series of function objects,
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that

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.