This tutorial gives the basics of Object Oriented Programming (OOP) in
C++. In programming, an object is used to group related data. In C++
this is done through classes. This tutorial assumes that the reader
has a basic knowledge of C++.

Class Basics

Here is the basic syntax of a class.

class Object
{
public:
//functions, variables, etc.

private:
//functions, variables, etc.
};

Data elements that are under public can be accessed outside of the
class but data under private cannot. Also, please note the required
semi-colon after the close bracket.

To create an instance of this object you would declare it like any
other data type:

Object object;

Let's look at an example:

class Person
{
public:
bool male;
int age;
bool GetMaritalStatus();

private:
bool single;
};

bool Person::GetMaritalStatus()
{
return single;
}

In OOP it is considered good style, as far as I know, for data under
public to be things that would be publicly accessed by anyone. In our
example, anyone should be able to tell if a person is male or not
(hopefully) and should also be able to roughly tell their age. Whether
a person is single or not, however, is usually not publicly available
so it is under private. The person may choose to release whether they
are single or not so there is a function in public, GetMaritalStatus,
that will return whether the person is single or not. This is called a
member function. Member functions are just like regular functions,
they can have parameters passed to them, output, anything that any
other function can do. Please note that you cannot initialize a variable for anything inside a
class without using a function. For example, we would get an error if,
when defining single, we wrote bool single=true. Note how the function is defined in the class but written outside of the class in the format of:

data type Class::Function().

This function also could have been written inside the class to look
like this:

public:
bool GetMaritalStatus()
{
return single;
}

It is proper style to write large functions outside of the class
because it is easier to read.

Constructors

If we were to create a person:

Person cire;

cire would habe no age or anything, this is where constructors come in.
They are member functions that are used to pass data to the class.
Contructors always use the same name of the class and do not have a
data type. Using our person example, here is how a constructor would
work:

class Person
{
public:
Person(int years, bool single, bool male);
bool male;
int age;
bool GetMaritalStatus();

private:
bool single;
};

Person::Person(int years, bool single, bool male)
{
age=years;
male=male;
single=single;
}

Now to create a Person, it would look like this:

Person cire(17,true,true);

To access a member function we would write:

cire.GetMaritalStatus();

which would return true.

Structures

There is another type of format for creating an object and that is
using a structure. The difference between a structure and a class is
that in a structure there is no private, every peice of data is public.
The structure for a structure (no pun intended) is:

struct Object
{
//variables, functions, etc.
};

This concludes this tutorial, but there is much more to C++ OOP
including inheritance which I may cover later. Hope this was
informative.