Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How do I make an argument in a function "optional"

This topic is 6059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In VB you could write Public Function (x as integer, optional i as integer) And I would only be used if it was included in the function. Is the only way to accomplish something like this by using overloaded functions, one of which contains the 2nd parameter, and one of which doesn''t?

Share this post

Link to post
Share on other sites
In C++, you assign the argument a value.

void foo(int a, int b = 0) {}

That makes b optional. Requirement is that all optional variables must be at the end of the argument list.

Note that it can take any value, not just 0. Just depends on how you want the value to be used if it's not supplied.

Edited by - dragonskin on February 21, 2002 3:17:32 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!