Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 ?

question from:https://stackoverflow.com/questions/5740296/missing-default-argument-compiler-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

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" ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...