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.