Skip to content

Instantly share code, notes, and snippets.

@qiaoxu123
Last active July 29, 2019 05:38
Show Gist options
  • Save qiaoxu123/8a5641fcd708a46472c423be3fe43c07 to your computer and use it in GitHub Desktop.
Save qiaoxu123/8a5641fcd708a46472c423be3fe43c07 to your computer and use it in GitHub Desktop.
`default`函数存在的问题,在于用户想要自定义函数进行类的初始化。此时类的默认构造函数需要显示进行定义。这是用户自定义的无参数的默认构造函数 此时定义的默认构造函数的功能和类模板原始的自定义构造函数的功能是相同的,但是效率变得非常低。在这使用`default`关键字,将用户自定义的无参数 的构造函数进行处理,这样编译器在处理的时候可以极大地提升效率。 --- [参考链接](https://www.ibm.com/developerworks/cn/aix/library/1212_lu
#include <iostream>
using namespace std;
class base {
public:
base() = default;
~base() = default;
private:
int num;
};
int main() {
cout << "Hello World" << endl;
return 0;
}
#include <iostream>
class X {
public:
virtual ~X() = default;
private:
int x;
};
class Y:public X {
private:
int y;
};
int main(){
X* x = new Y;
delete(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment