Module 4 · Lesson 1 of 29/26 in the course~14 min
Module lessons (1/2)
Classes and Objects
Lesson preview5 hands-on exercises readyCourse C++ · Module 4 — Object Oriented Programming
The syntax class, data members and member functions. Access specifiers public and private for encapsulation.
What you'll learn in this lesson
- Design user-defined types with
classandstruct(always ending with;). - Protect internal invariants with
private:by exposing checked methodspublic:. - Declare read-only methods as
constto also work withconst T¶meters.
Overview
Object Oriented Programming in C++ adds no hidden costs: a class without virtual functions occupies exactly the same space in bytes as a struct in C, but packs data (membri) and behavior (metodi) in the same place.
Inside a class, all members are private by default (as opposed to struct, where the default is public):
Sections covered in this lesson
- 11. Syntax of
class,private:andpublic: - 22.
classvsstruct: What Really Changes? - 33. Methods
const(Const-Correctness) - 44. The Pointer
this - 5Practical exercises
- 6Check for understanding
Pro Lesson · Module 4 — Object Oriented Programming
Unlock "Classes and Objects" and the full Course C++ curriculum
The syntax class, data members and member functions. Access specifiers public and private for encapsulation.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course C++ plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.