C++ essentialsObject-oriented
Classes & objects
8 min lesson
A class defines a type that combines data and functions. An object is one value created from that class, with its own state.
Keep in mind
Keep data private and expose a small public interface to control how an object is used.
lesson.cpp
#include <string>
class Course {
public:
explicit Course(std::string title) : title_(title) {}
const std::string& title() const { return title_; }
private:
std::string title_;
};What happens: Course objects keep their title and expose it through title().