casting to structure
Igor Shirkalin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 24 13:43:48 PDT 2017
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?
More information about the Digitalmars-d-learn
mailing list