Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
class is a keyword to start a class declaration. A class is a user-defined data type with multiple elements and access levels. A class has data members, member functions and free functions.
The class keyword also be used to create a template function.

Example class
class MyClass |
Don't forget the semicolon at the end of the class definition!

Class elements
A class can have many types of members:
struct MyClass |
All classes have a four special methods called the Big Four: default constructor, destructor, copy constructor and copy assignment operator:
struct NoClass {}; //Do all classes really have a constructor, destructor, |
This class called NoClass is silently converted by your compiler to the following (from [1]):
struct NoClass |
Know what functions C++ silently writes and calls [1].

Class access levels
A class has three different access levels: public, private and protected. A class' default for functions and variables is private. This is the only (!) difference with a struct, which has public as its default access level.
struct MyClass |

Class types
Examples of class types are:

Abstract base class
Base class
Derived class
Enum class
Functor
Template class
Winnebago class: a do-it-all class

Class design
See class design for some guidelines on class design.
Design patterns are standarized class designs to achieve a certain goal, often involving multiple classes.

Example classes
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.