1.首先,对于内置类型,低精度的变量给高精度变量赋值会发生隐式类型转换。
2.其次,对于只存在单个参数的构造函数的对象构造来说,函数调用可以直接使用该参数传入,编译器会自动调用其构造函数生成临时对象。
#include<iostream>
using namespace std;
class person
{
public:
person(int x)
{
age = x;
cout << this->age << endl;
}
private:
int age;
};
int main()
{
person(5);// 无需手动创建对象 直接传入参数即可 编译器会自动调用其构造函数 生成临时对象
system("pause");
return 0;
}