Missing default argument - compiler error

user478571 picture user478571 · Apr 21, 2011 · Viewed 52.7k times · Source
void func ( string word = "hello", int b ) {

  // some jobs

}

in another function

 //calling 
 func ( "", 10 ) ;

When I have compiled it, compiler emits error ;

default argument missing for parameter 

How can I fix it without changing anything, of course, such as not making "int b = 0" ? Moreover, I want use that function like func ( 10 ) or func ( "hi" ) ? Is my compiler not do its job, properly ?

Answer

cnicutar picture cnicutar · Apr 21, 2011

You can't have non-default parameters after your default parameters begin. Put another way, how would you specify a value for b leaving word to the default of "hello" ?