3 Object-Oriented Programming in C++
C++ Object-Oriented Programming, Classes, and Objects
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:
- Default member access: members of a
structarepublicby default, while members of aclassareprivateby default. - Default inheritance access: when deriving with
struct Derived : Base, the inheritance ispublicby default; when deriving withclass Derived : Base, it isprivateby default — regardless of whetherBaseitself 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
