Opening the Black Box: Legally Testing Private Members in C++

Hubert Liberacki

⏱ 20 minute session
intermediate
advanced
15:00-15:30, Friday, 19th June 2026

Encapsulation is a cornerstone of C++, yet real-world development sometimes requires access to private members. Refactoring legacy code, testing third-party libraries, or debugging complex systems can all make such access necessary.

This talk looks at why common approaches to testing private members, such as macro tricks or layout-based hacks, are fragile and often rely on undefined behaviour. It then presents a standards-compliant technique that allows controlled access to private members without invoking undefined behaviour, and without breaking encapsulation, object layout, or portability.


🏷 templates
🏷 testing

Hubert Liberacki

Hubert Liberacki has over a decade of experience in C++, working on performance-critical and distributed systems in automotive, robotics, and large-scale software platforms. He currently works on large C++ systems for maps and rendering at HERE Technologies and is interested in Rust and systems programming.