default arguments in constructor

后端 未结 5 1985
失恋的感觉
失恋的感觉 2021-01-15 16:52

Can I use default arguments in a constructor like this maybe

Soldier(int entyID, int hlth = 100, int exp = 10, string nme) : entityID(entyID = globalID++), hea

5条回答
  •  星月不相逢
    2021-01-15 17:14

    I believe you can do this, however, all your defaulted args would need to go at the end. So, in your example, the constructor signature would be

    Soldier(int entyID, string nme, int hlth = 100, int exp = 10);
    

提交回复
热议问题