1. 使用=default来要求编译器生成一个默认构造函数
struct Point{
Point() = default;//不用像下面的构造函数一样要一一对成员变量赋值
Point(int _x, int _y):x(_x),y(_y){
}
int x=0;
int y=0;
};
eg.
// use of defaulted functions
#include <iostream>
using namespace std;
class A {
public:
// A user-defined
A(int x){
cout << "This is a parameterized constructor";
}
// Using the default specifier to instruct
// the compiler to create the default implementation of the constructor.
A() = default;
};
int main(){
A a; //call A()
A x(1); //call A(int x)
cout<<endl;
return 0;
}