© Slobodan Dmitrović 2020
S. DmitrovićModern C++ for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6047-0_23

23. Classes - Introduction

Slobodan Dmitrović1 
(1)
Belgrade, Serbia
 
Class is a user-defined type. A class 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 MyClass. Then we created an object o of type MyClass. It is said ...

Get Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 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.