c++新特性11 (6) =default
生活随笔
收集整理的这篇文章主要介绍了
c++新特性11 (6) =default
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
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-definedA(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; }总结
以上是生活随笔为你收集整理的c++新特性11 (6) =default的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: LevelDB (1)概述
- 下一篇: c++新特性11 (10)shared_