3 Object-Oriented Programming in C++

C++ Object-Oriented Programming, Classes, and Objects
Author

Daniel Schwarzenbach

work in progress

The Idea of Object-Oriented Programming

Classes in C++

Classes and structs are almost the same in C++. There are only two real differences between them:

  1. Default member access: members of a struct are public by default, while members of a class are private by default.
  2. Default inheritance access: when deriving with struct Derived : Base, the inheritance is public by default; when deriving with class Derived : Base, it is private by default — regardless of whether Base itself is a struct or a class.

People argue all the time about whether to use struct or class. I personally prefer to use struct all the time, since making things private by default is ussually not a good idea. But this is a matter of taste, and you should do what you feel is best.

Why make something private?

Member Functions

Special Member Functions

Rule of Zero

Rule of 3

Rule of 5

Inheritance

Inheritance Diagram of std::iostream