to remove two-column,resize your browser window to narrow

clever use of enum(char?) in demanding c++ app

Requirement — we need to down cast a Base pointer. dynamic_cast has overhead.

Der* returnVal = static_cast (new Base) // will compile but is potentially disastrous, because the returnVal can be a partially wild pointer.

Q: without incurring the overhead of vtbl lookup, how do I decide if a pointer to Base given to me actually points to a Base or Der instance?

%%A: type_info still uses vtbl.%%A: use a Base field to indicate the type. Both ctor will set the field, so the Der ctor will overwrite.A: enum. If sizeof(aBase) is a tiny 2 bytes, then adding an enum field adds just 1 byte. Adding vptr would add 4 bytes. Big difference if we instantiate billions of this class. I guess enum can be configured to take 1 byte, but you can also use a char, which is always 1 byte.