Class basics

suggest change

A class is a user-defined type. A class is introduced with the class, struct or union keyword. In colloquial usage, the term “class” usually refers only to non-union classes.

A class is a collection of class members, which can be:

The class and struct keywords, called class keys, are largely interchangeable, except that the default access specifier for members and bases is “private” for a class declared with the class key and “public” for a class declared with the struct or union key (cf. access modifiers).

For example, the following code snippets are identical:

struct Vector
{
    int x;
    int y;
    int z;
};
// are equivalent to
class Vector
{
public:
    int x;
    int y;
    int z;
};

By declaring a class` a new type is added to your program, and it is possible to instantiate objects of that class by

Vector my_vector;

Members of a class are accessed using dot-syntax.

my_vector.x = 10;
my_vector.y = my_vector.x + 1; // my_vector.y = 11;
my_vector.z = my_vector.y - 4; // my:vector.z = 7;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Classes / structs:
* Class basics

Table Of Contents
8 Arrays
11 Loops
19 Classes / structs
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype