No subject
     
    
       
    Sat Nov 15 23:40:05 PST 2008
    
    
  
incompatible types that just happen to be the same under the hood.
> typedef int BlockNum;
> BlockNum a = cast(BlockNum) 42;
> someFuncThatTakesAnInt(cast(int) a);
The last is if you need something that's basically an int, but you want
it to behave differently.  In that case, a struct with operators is your
best bet.
Let's say you wanted to do something like a Meters struct to store
lengths.  I'd do something like this:
> struct Meters {
>     private int value;
>     int asInt() { return value; }
>     int asInt(int v) { return value=v; }
>     // ... operator overloads ...
> }
>
> Meters a; a.asInt = 42;
> someFuncThatTakesAnInt( a.asInt );
I can't really offer more than that, since I don't know what it is
you're trying to accomplish.
  -- Daniel
    
    
More information about the Digitalmars-d-learn
mailing list