Archived

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

amemorex

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

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