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

Pages: 1-

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:33

TERRIBLE!!!

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".

Name: Anonymous 2011-04-15 9:18

>>3
implicit conversions to allow expressions like "obj + 1".
Why this?

Name: Anonymous 2011-04-15 9:49

>>4
Why not? You want you dynamic type system to integrate with the host type system as seamlessly as possible. Also, see dynamic things in C#.

Name: Anonymous 2011-04-15 11:37

>>5
Implicit conversions are the root of all evil. See Programmers Hate Personal Home Page: Happy Programmers and JavaScript.

Name: Anonymous 2011-04-15 13:42

DICENTIS,
 EGO SVM ABELSON ET SVSSMAN,
 PRIMVS ET RELIQVVS,
 CARVS ET CVDDARVS.

Name: Anonymous 2011-04-15 13:44

DICENTIS,
 EGO SVM ABELSON ET SVSSMAN,
 PRIMVS ET RELIQVVS,
 CARVS ET CVDDARVS.

Name: Anonymous 2011-04-15 13:46

DICENTIS,
 EGO SVM ABELSON ET SVSSMAN,
 PRIMVS ET RELIQVVS,
 CARVS ET CVDDARVS.

Name: Anonymous 2011-04-15 13:47

DICENTIS,
 EGO SVM ABELSON ET SVSSMAN,
 PRIMVS ET RELIQVVS,
 CARVS ET CVDDARVS.

Name: Anonymous 2011-04-15 13:49

DICENTIS,
 EGO SVM ABELSON ET SVSSMAN,
 PRIMVS ET RELIQVVS,
 CARVS ET CVDDARVS.

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