© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
S. DmitrovićModern C++ for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-9274-7_23

23. Classes – Introduction

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 
A class is a user-defined type. It consists of members. The members are data members and member functions. A class can be described as data and some functionality on that data, wrapped into one. An instance of a class is called an object. To only declare a class name, we write
class MyClass;
To define an empty class, we add a class body marked by braces {}:
class MyClass{};
To create an instance of the class, an object, we use:
class MyClass{};
int main()
{
    MyClass o;
}

Explanation:

We defined a class called ...

Get Modern C++ for Absolute Beginners: A Friendly Introduction to the C++ Programming Language and C++11 to C++23 Standards now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.