|
Re: Bridging Static and Dynamic Typing
|
Posted: Apr 17, 2006 5:14 AM
|
|
Coding a Variant class in C++ is no problem at all. Unfortunately, C++ does not offer 'variant' semantics, so it takes more code to use a 'variant' instance properly. If a variant is used in expressions, then operators can be passed in the underlying object as messages (i.e. virtual methods). But there is no way to call a method of an object of a variant instance without casting the variant to a type, which makes the whole issue of using 'variant' more of a problem than a solution.
In other words, one can happily do in C++ the following:
var x = 5; x += 1; cout << x; var y = x; y = "the quick brown fox";
But the following is not possible:
var x = new foo; x->bar();
unless one does this:
foo *f = (foo *)x; f->bar();
which makes using 'var' reduntant, since we are going to type 'foo' anyway. Not only that, but it makes it very dangerous, because if I change 'foo' to 'bar' and then I forgot to update references to 'foo' in other places, then my program will certainly crash.
|
|