How to simulate a new type

tired_eyes via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 15 01:30:16 PDT 2015


On Friday, 15 May 2015 at 06:11:41 UTC, Charles Hixson wrote:
>
>
> On 05/14/2015 06:38 PM, Adam D. Ruppe via Digitalmars-d-learn 
> wrote:
>> On Friday, 15 May 2015 at 01:03:32 UTC, Charles Hixson wrote:
>>> Yes, that looks as if it would do the job, but what are its 
>>> advantages over a simple struct?
>>
>> None really, except perhaps automatic forwarding of operators 
>> which is easy enough to do on a struct too (and with a struct, 
>> you can do only the ones that actually make sense for you).
>>
>> Typedef has a few major disadvantages too - surprising 
>> behavior if you forget the second parameter, for example. The 
>> library typedef should really be removed.
>>
> Thank you.  I was hoping that struct was a good approach, I've 
> just never seen anyone recommending it, so I wanted to check.

FWIW, I've seen a lot of user-defined types made with structs in 
the code of C-ported libs, and was sure that is a common approach.


More information about the Digitalmars-d-learn mailing list