compiler construction - Is this C++ code portable? -



compiler construction - Is this C++ code portable? -

struct { int a; virtual void print() {} }; struct b : { int b; virtual void print() {} }; int main(void) { *a = new b; a[0].print(); // g++, vs2010, clang phone call b::print. }

all 3 g++, vs2010, clang phone call b::print. doubting c++ 101. under impression using dot object not result in dynamic dispatch. -> pointer , dot reference result in dynamic dispatch.

so question whether code portable?

a[0] same *a, , look reference a, , virtual dispatch happens through references through pointers. a->print() , (*a).print() exclusively identical.

c++ compiler-construction virtual portability

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -