c++新特性11 (6) =default
生活随笔
收集整理的這篇文章主要介紹了
c++新特性11 (6) =default
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1. 使用=default來要求編譯器生成一個默認構(gòu)造函數(shù)
struct Point{ Point() = default;//不用像下面的構(gòu)造函數(shù)一樣要一一對成員變量賦值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; }總結(jié)
以上是生活随笔為你收集整理的c++新特性11 (6) =default的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LevelDB (1)概述
- 下一篇: c++新特性11 (10)shared_