adisar86
adisar86

Reputation: 11

New to C++, signature definition

I have a function written in C++:

foo (IN bool someMode = false)

What does that mean? Will someMode always be initialized to false? Even if foo is called with true?

Upvotes: 0

Views: 72

Answers (3)

Michael Anderson
Michael Anderson

Reputation: 73480

Typically IN is macro that does nothing, and just lets you know that an argument is an input to the function, so what you really have is foo(bool someMode=false). What you're left with is a default argument. This means you can call the code like this:

foo(true); // Here someMode=true
foo(false); // Here someMode=false

or like this

foo(); // Here someMode=false

Upvotes: 0

jka6510
jka6510

Reputation: 826

Its a default parameter, allowing you to omit it, basically, if you call:

foo();

then someMode will still exist, and be set to false, but if you call

foo(true);

then someMode will be true.

Upvotes: 0

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361412

It means even though foo takes one argument, you can call this function without passing any argument as:

 foo(); //ok

If you call like this, then someMode value will be false, as that is what its default value is. someMode = false in the function signature means, if no argument is passed, then someMode will be false. In programming, such a parameter is said to be default parameter, and false in this context is said to be default value for the parameter.

However, if you wish, you can pass argument:

foo(false); //ok 
foo(true);  //ok

Upvotes: 3

Related Questions