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 August 4, 2025 17:25
Explicit type conversion (cast notation)
struct Parent { virtual ~Parent(); };
struct Child : private virtual Parent { };
int main()
{
Child aa;
Parent& pp = (Parent&)(aa); // OK ( [expr.cast]/p4.6 ), chooses static_cast
Child& aa = (Child&)(pp) // FAILS, chooses static_cast, but that would fail
// because Parent is a virtual base ( [expr.static.cast]/p2 )