You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classDate{
int d, m, y;
public:explicitDate(int dd = 0, int mm = 0, int yy = 0);
};;
Date d1{15}; //正确,被看成是显式类型转换
Date d2 = Date{15}; //正确,被看成是显式类型转换
Date d3 = {15}; //error:=初始化不能进行隐式类型转换
Date d4 = 15; //error:=初始化不能进行隐式类型转换voidf(){
my_fct(15); //error:参数传递不能进行隐式类型转换my_fct({15}); //error:参数传递不能进行隐式类型转换my_fnt(Date{15}); // ok :显式类型转换
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
explicit 的主要用法就是放在单参数的构造函数中,防止隐式转换, 导致函数的入口参数, 出现歧义
Beta Was this translation helpful? Give feedback.
All reactions