C++ 构造函数的默认参数

默认参数需要写在函数声明位置,函数体定义时不需要写默认参数。

(√)

int func(int=1);
int func(int a){};

(×)

int func(int);
int func(int a=1){};

(×)

int func(int=1);
int func(int a=1){};

默认参数必须从参数列表的右端开始。

(√)

int boxVolume( int length, int width = 1, int height = 1 );

(×)

int boxVolume( int length = 1, int width, int height = 1 );

原文地址:https://www.cnblogs.com/mollnn/p/12598942.html