- 01Getting Started
- 02Your First Output (cout)
- 03Variables and Types (int/double/string/bool)
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Pointer Basics
- 10References
- 11Classes (Object-Oriented Programming)
- 12Constructors and Destructors
- 13Inheritance
- 14Using vector (the Standard Library)
- 15String Manipulation (string)
- 16Structs (struct)
- 17Error Handling (try/catch)
- 18The Ternary Operator
- 19The switch Statement
- 20[Applied] Build a Mini Inventory Management System
Classes (Object-Oriented Programming)
This lesson covers the basics of writing a class in C++. It's for anyone searching "C++ class usage."
A class bundles data (member variables) and logic (member functions) together. Use public: to specify which members can be used from outside the class.
The example defines class Animal, with a member variable name and a member function, speak(), that returns a sound.
A common early mistake is forgetting to write public:. In C++, a class's members are private by default, so you need to explicitly mark anything you want to use from outside as public:.
In real projects, classes are used to represent data that bundles state and behavior together โ a game character, or an element in a simulation.
๐งช This site can't compile or run C++ directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
