Object-Oriented C++
Classes, special member functions, inheritance, polymorphism and run-time type information. Classes and objects, constructors and destructors, copy/move semantics, inheritance, virtual functions and abstract classes have their own pages earlier in this subject.
This is an overview — pick a sub-topic below.
Sub-topics (13)
Copy Constructor
`T(const T& other)` creates a new object as a copy.
Move Constructor
`T(T&& other) noexcept` transfers resources from a temporary instead of copying.
Copy Assignment
`T& operator=(const T& other)` replaces an existing object's contents with a copy.
Move Assignment
`T& operator=(T&& other) noexcept` replaces contents by stealing from a temporary.
Multiple Inheritance
A class deriving from several bases.
Polymorphism in C++
One interface, many implementations: compile-time (templates, overloading) and run-time (virtual functions).
Encapsulation
Hide data behind `private`/`protected` and expose a minimal `public` interface.
Friend Functions and Classes
`friend` grants another function or class access to private members.
Nested Classes
A class defined inside another — scoped to it, often for helpers like iterators or nodes.
Static Members
Members shared by all objects of a class.
RTTI
Run-Time Type Information: `typeid` and `dynamic_cast` on polymorphic types.
dynamic_cast
Safely downcast a base pointer/reference to a derived type, checking at run time.
Virtual Destructors
A base class used polymorphically needs a `virtual` destructor.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.