下面这段代码
int a = int();
cout<<a<<endl;
输出是0;
我想知道这个int()是什么用法。或者您可以告诉我用什么名词可以搜索到这个内容,我想具体得了解一下。
伊谢尔伦2017-04-17 13:53:31
Keywords: constructor
For a type, the type name itself is the constructor of the type
For example, there is a class
class A {
...
};
Then A() is the constructor of type A. Using A() you can get a variable of type A.
int is a built-in type, so int() calls the constructor of the int type and returns an int variable.