C++

44 articles in this topic

C++ Encapsulation and Class Invariants: Build Objects That Stay Valid

Learn to design a C++ BankAccount that cannot be created or changed into an invalid state. Trace constructor checks, guarded operations, representation leaks, and boundary tests.

Updated 17 Sep 20265 min readC++

C++ deque, list and forward_list: Choose the Right Non-Vector Container

Use one controlled sequence-editing workload to compare deque, list and forward_list. See where search cost, iterator validity and memory locality change the decision.

Updated 16 Sep 20266 min readC++

C++ Composition vs Inheritance: Choose the Stable Relationship

Follow one C++ notification design from eight combination subclasses to three replaceable policies. The worked trace shows exactly where inheritance still fits.

Updated 14 Sep 20266 min readC++

C++ Lambda Expressions: Capture Rules, Closures and STL Patterns

Learn to read C++ lambdas, trace copied and referenced state, write a valid sort comparator, and prevent dangling-reference bugs in stored callbacks.

Updated 13 Sep 20265 min readC++

C++ Fundamental Types and Conversions: Predict Values from the Bits

Learn a repeatable way to predict C++ expression types and values by tracing representations, promotions, common types, and final storage conversions.

Updated 11 Sep 20266 min readC++

C++ Function Overloading and Default Arguments: Resolve Valid and Ambiguous Calls

Learn why default arguments affect viability but not ranking, then resolve five score calls using exact matches, promotions and conversions. Includes ambiguity repairs and call-time default evaluation.

Updated 10 Sep 20266 min readC++

C++ Exception Handling: Typed Errors, Stack Unwinding and Safe Recovery

Build a small C++ parser that reports machine-readable failures, recovers only from a malformed optional field, and preserves saved state when a required field fails.

Updated 8 Sep 20266 min readC++

C++ enum class, struct, pair and tuple: How to Model Small Data Safely

Model Ticket 417 three ways, calculate the same response window, then add an owner to see why named fields often beat positional access in changing code.

Updated 7 Sep 20266 min readC++

C++ const, constexpr and consteval: Runtime Immutability vs Compile-Time Guarantees

See exactly what each C++ keyword guarantees. One C++20 program separates immutability, optional constant evaluation and mandatory constant evaluation.

Updated 5 Sep 20266 min readC++

C++ Compiler Warnings and Sanitizers: Catch Bugs Early

Build a practical C++ safety net with strict warnings and sanitizer runs. Three small programs show how to find, explain and fix defects before they spread.

Updated 4 Sep 20266 min readC++

C++ Arrays vs std::array vs std::span: Choose the Right Interface

Run the same five integers through raw-array, std::array and std::span interfaces, then choose from their ownership, size and lifetime contracts.

Updated 2 Sep 20266 min readC++

C++ Classes and Objects MCQs: 11 Solved Questions on Members, Pointers and Inheritance

Work through 11 C++ classes and objects MCQs, then use the fresh explanations and fixed examples to repair mistakes in access, lifetime and inheritance rules.

Updated 1 Sep 20268 min readC++