Hello!

I'm in trouble with opCast function.
Is it possible to cast some (integral) type to user defined structure?

We have a structure:

struct A
{
  void * data; // void * type is just for example
  // no matter what is here
}

How can we define opCast operator to make the following expression working properly?

auto a = cast(A) 12;

The task arised from core.sys.windows module. This module defines a lot of windows specific types based on HANDLE: these are HWND, HDC, HBITMAP, etc. The problem is that all these types are identical, and it is too bad. When I redefine these types like:
       alias Typedef!(void*) HDC;

I have another problem:

HWND_MESSAGE = cast(HWND) -3; // Error: cannot cast expression -3 of type int to Typedef!(void*, null, null)

So, is there any solution to this?



Reply via email to