J
Jim Langston
I wound up creating a null reference on accident using polymorphism and
wondered if this snippet is legal code, as it compiles and works as I would
expect it to work.
void jglRenderModel( jglModel& model ) {
if ( &model == nullptr ) {
return;
}
/* ... */
}
// Following line may produce a nullptr reference
jglRenderModel( *dynamic_cast<jmlGL::jglModel*>((world.objects.find(
L"Cube" ))->second) );
// Following line will produce a nullptr reference
jglRenderModel( *reinterpret_cast<jmlGL::jglModel*>( nullptr ) );
wondered if this snippet is legal code, as it compiles and works as I would
expect it to work.
void jglRenderModel( jglModel& model ) {
if ( &model == nullptr ) {
return;
}
/* ... */
}
// Following line may produce a nullptr reference
jglRenderModel( *dynamic_cast<jmlGL::jglModel*>((world.objects.find(
L"Cube" ))->second) );
// Following line will produce a nullptr reference
jglRenderModel( *reinterpret_cast<jmlGL::jglModel*>( nullptr ) );