How would You make abstract HANDLE?

Simon s.d.hammett at gmail.com
Wed Jan 19 10:23:43 PST 2011


On 19/01/2011 12:27, Mariusz Gliwiński wrote:
> How to make a HANDLE in D without casting and stuff:
> <code>
> interface iface{
> void doSomething(HANDLE h);
> }
> class A : iface {
> override void doSomething(HANDLE h) {
> assert(validPointer(h));
> h.foo = bar;
> }
> }
> class B : iface {
> someVar table[];
> override void doSomething(HANDLE h) {
> assert(table.isInBounds(h));
> table[h].foo = bar;
> }
> </code>
>
> Module/class -scoped alias would be great like:
> <code>
> #a.d
> private alias uintptr_t HANDLE;
>
> #b.d
> private alias someVar HANDLE;
> </code>
>
> but alias is resolved too early for that. How to make it properly then?
> Union or something else?
>
> Thanks,
> Mariusz Gliwiński

Traditionally:

struct dummy;

alias dummy* HANDLE;

void doSomething(HANDLE h) {
}

Just don't provide a body for dummy to keep it abstract.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list