Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
dgodfrey206 / etc.cpp
Created April 19, 2015 20:24
More explicit type conversion
#include <new>
struct Parent { };
struct Child : Parent { };
struct Tag { };
int main()
{
const Child c;
@dgodfrey206
dgodfrey206 / cast.cpp
Last active October 25, 2025 21:39
Explicit type conversion (cast notation)
struct Parent { virtual ~Parent() = default; };
struct Child : private virtual Parent { };
int main()
{
Child c0;
Parent& p0 = static_cast<Parent&>(c0); // FAILS, Parent is inaccessible
Parent& p1 = (Parent&)(c0); // OK ( [expr.cast]/p4.6 ), chooses static_cast