C++ 中的平凡類


本教程中,我們討論一個程式來了解 C++ 中的平凡類。

當一個類/結構內部包含顯式預設值時,它就被稱為平凡類。此外,平凡類有自己的構造器、賦值運算子和析構器。

示例

//using the default constructor
struct Trivial {
   int i;
   private:
   int j;
};
//defining your own constructor
//and then marking it as default
struct Trivial2 {
   int i;
   Trivial2(int a, int b){
      i = a;
   }
   Trivial2() = default;
};

輸出

(No output as we are just defining classes here and not creating object instances from them.)

更新於:2020 年 3 月 12 日

345 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.