Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Dynamic typing in C++

Name: Anonymous 2011-04-15 8:21

This shit could work:

1. Derive every single fucking class from class Object.

2. Make every fucking method return only Objects and accept only Object references as parameters

3. dynamic_cast everything

4. throw exceptions if dynamic_cast fails

why didn't I think of this before

Name: Anonymous 2011-04-15 8:54

>>1
That's retarded. You still fully use static types, as arguments to your dynamic_casts; type information is being in erased state only between a function invocation (where you upcast all parameters to Objects) and the moment when you downcast them back. That doesn't gain you almost anything.

The correct way to do dynamic typing in C++ is to make your own Object class loosely based on std::map, with obj["attribute"] as attribute access. Then add a shitton of operators and implicit conversions to allow expressions like "obj + 1".

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List