"C ++ Standard Library" -1

explicit keywords

On this key principle only constructor function, inhibition of negative conversion, for example:

class String{

  String(int size); //本意是要申请size大小的字符串

};

If the call at this time

String s1(20);  //成功申请20个大小长度的字符串

String s2 = 20; //同上

String s3 = 'a'; //本意是要把a赋值给s3,结果是 申请了a字符对应大小的字符串

In this case the original becomes a function declaration

class String{

  explicit String(int size);

};

This will suppress s3 = 'a' stealth conversion

 

static_cast

Use a temporary reconstruction of the original value of the object, and use the type conversion when setting up the initial value

Such as

float x;

cout << static_cast<int>(x)<<endl; //把x转换为float输出

 

Standard C ++ main () Definition Format

int main(){

...

}
int main(int argc,char* argv[]){ ... }

The last may be omitted return 0; automatically add an implicit return 0;

Reproduced in: https: //my.oschina.net/u/204616/blog/545020

Guess you like

Origin blog.csdn.net/weixin_33752045/article/details/91989504