Tag: inheritance
8 posts
-
Missing Virtual Destructor: Why Deleting Through a Base Pointer Leaks or Worse
Why deleting via a base pointer without a virtual destructor is undefined behavior, what GCC warns about, why unique_ptr<Base> hits it but shared_ptr hides it.
-
C++ Slicing Bugs: Finding Where a Base-Type Copy Dropped Your Derived Object
How C++ object slicing silently drops derived data in by-value parameters, vector<Base>, catch by value and base assignment, and how to make it a compile error.
-
C++ Name Hiding: Why a Derived Function Hides Base Overloads and How using Fixes It
Why a derived-class function hides every base-class overload with the same name, why the dangerous case compiles and silently calls the wrong function, and how using-declarations and -Woverloaded-virtual prevent it.
-
Python Classes: Class vs Instance Attributes, super() and the MRO, @property and Dataclasses
How Python classes work: the shared mutable class attribute bug, __new__ vs __init__, super() and the MRO, @property, dataclasses and __hash__.
-
JavaScript Classes | ES6 Class Syntax Explained
JavaScript ES6 classes explained: what class syntax desugars to, getters/setters, static blocks, inheritance, private fields (#), and the this-binding pitfall.
-
C++ Object Slicing: Why Derived State Disappears and How to Prevent It
Why copying a derived object into a base value drops its state and overrides, where slicing hides (catch clauses, vectors, throw e;), and how to block it.
-
C++ Inheritance Design: Access Specifiers, Virtual Destructors, Hiding and Diamonds
C++ class hierarchy design: public vs private inheritance, virtual destructors, virtual calls in constructors, name hiding, slicing and virtual bases.
-
The Decorator Pattern in C++: Adding Behavior by Composition (Streams, Logging, Formatters)
The Decorator pattern in C++: adding behavior at runtime through composition instead of inheritance, with stream decorators, a logging system, and a text formatter example.