ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อทำความเข้าใจคลาสย่อยในภาษา C++
เมื่อคลาส/ struct มีค่าดีฟอลต์ที่ชัดเจนอยู่ภายใน คลาสนั้นเรียกว่าคลาส Trivial ชั้นเรียนที่ไม่สำคัญเพิ่มเติมจะมีตัวสร้าง ผู้ดำเนินการมอบหมาย และตัวทำลายล้างของตัวเอง
ตัวอย่าง
//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.)