Missing default argument - compiler error

前端 未结 5 976
無奈伤痛
無奈伤痛 2021-01-31 15:17
void func ( string word = \"hello\", int b ) {

  // some jobs

}

in another function

 //calling 
 func ( \"\", 10 ) ;

When I have compiled it, compi

5条回答
  •  被撕碎了的回忆
    2021-01-31 15:56

    The error message is proper. If the default argument is assigned to a given parameter then all subsequent parameters should have a default argument. You can fix it in 2 ways;

    (1) change the order of the argument:

    void func (int b, string word = "hello");
    

    (2) Assign a default value to b:

    void func (string word = "hello", int b = 0);
    

提交回复
热议问题