Missing default argument - compiler error

前端 未结 5 946
無奈伤痛
無奈伤痛 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条回答
  •  旧时难觅i
    2021-01-31 16:20

    You cannot fix it without changing anything!

    To fix it, you can use overloading:

    void func ( string word, int b ) {
      // some jobs
    }
    
    void func ( string word ) {
        func( word, 999 );
    }
    
    void func ( int b ) {
        func( "hello", b );
    }
    

提交回复
热议问题