When a class or struct in C++ has compiler-provided or explicitly defaulted special member functions, then it is a trivial type. It occupies a contiguous memory area. It can have members with different access specifiers.
Trivial types have a trivial default constructor, trivial copy constructor, trivial copy assignment operator and trivial destructor. In each case, trivial means the constructor/ operator/ destructor is not user-provided and belongs to a class that has :
- No virtual functions or virtual base classes,
- No base classes with a corresponding non-trivial constructor/operator/destructor
- No data members of class type with a corresponding non-trivial constructor/operator/destructor
The following examples show trivial types :
Reference : https://msdn.microsoft.com/en-us/library/mt767760.aspx
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- C++ Classes and Objects
- Anonymous classes in C++
- Nested Classes in C++
- Local Classes in C++
- Storage Classes in C++ with Examples
- C++ Stream Classes Structure
- File Handling through C++ Classes
- Virtual functions in derived classes
- How to add reference of an object in Container Classes
- Mutual friendship of Classes in C++ with Examples
- Pure Virtual Functions and Abstract Classes in C++
- Catching base and derived classes as exceptions
- Enum Classes in C++ and Their Advantage over Enum DataType
- Difference between cout and puts() in C++ with Examples