Having trouble with objects.

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Mar 18 16:35:02 PDT 2008


"Jarrod" <qwerty at ytre.wq> wrote in message 
news:frpi9g$1avh$1 at digitalmars.com...

>
> Well yeah the node acts much like a variant. And yes, it internally uses
> a union with an enum to keep track of the stored value type.
> It tries its best to convert the stored value to the desired type upon
> being called. My problem isn't with storing or handling the abstract
> data, it's that I need to use an overloaded function call to get the
> value. It's quite ugly and results in a lot of temporary variables being
> created when they don't need to be created, like for instance if I wanted
> to pass a number to a function:
>>int temp;
>>myNode.getValue(temp);
>>someFunc(temp);

This is precisely where a templated method would come in, as you've noticed:

someFunc(myNode.to!(int));

Sure, you don't get the cast syntax, but it's actually less typing and 
doesn't require fancy languages support.

Implicit casting in this case would be nice though.  D2 is apparently 
getting overloadable opImplicitCast at some nebulous time in the future. 




More information about the Digitalmars-d-learn mailing list