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
Post a Comment