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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:15:07+00:00 2026-06-07T13:15:07+00:00

I have a function like this: void foo(int optionalinteger=0, float optionalfloat=0.0f, cell *optionalarray=NULL) {

  • 0

I have a function like this:

 void foo(int optionalinteger=0, float optionalfloat=0.0f, cell *optionalarray=NULL)
 {
          return;
 }

I tried to acces an optional argument like

 foo(.optionalfloat=5.5f); // from another programming language

but that gives an error.
How do I access only the optional value I choose to without the need to supply other optional values?

  • 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-07T13:15:09+00:00Added an answer on June 7, 2026 at 1:15 pm

    If you really want to, you can use something akin to the named parameter idiom, e.g.:

    struct cell;
    
    void foo(int optionalinteger, float optionalfloat, cell *optionalarray) {}
    
    struct foo_params {
      foo_params& integer(int v) { integer_ = v; return *this; }
      foo_params& fl(float v) { fl_ = v; return *this; }
      foo_params& array(cell *v) { array_ = v; return *this; }
    
      // C++11 defaults for laziness, easy to change though
      int integer_=0;
      float fl_=0.0f;
      cell *array_=nullptr;
    };
    
    void foo(foo_params params = foo_params()) {
      foo(params.integer_, params.fl_, params.array_);
    }
    
    int main() {
      foo(foo_params().integer(100)
                      .array(0));
    }
    

    That’s quite a lot of work for something quite simple and counter-intuitive if you’re not really expecting to see something like that in your code base.

    Or you could use the boost named parameter library if you prefer.

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

Sidebar

Related Questions

Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
I have a function as such: int foo(void *val){ (char *)val=Long String; return 0;
I have function that receives an array of pointers like so: void foo(int *ptrs[],
I have a function similar to this: void foo(obj ary[], int arysize) { for
I have a function like this void doSmth(Long... paramg){ } But I can't pass
I have a function using strtok like this void f1(char *name) { ... char
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
I have a function like this in actionscript3 private function uploadFile(event:MouseEvent):void { var uploader:URLRequest
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
I would like to have a mapping function that does this: public static void

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.