Cast a struct to void*
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 9 10:36:44 PST 2015
On 01/09/2015 10:25 AM, John Colvin wrote:
> struct S
> {
> void* p;
> }
>
> void main()
> {
> S s;
> auto a = cast(void*)s; //Error: e2ir: cannot cast s of type S to
> type void*
> }
>
> Is there are a good reason for this being disallowed?
I know two options:
a)
alias p this;
b)
auto opCast(T : void*)()
{
return p;
}
Ali
More information about the Digitalmars-d-learn
mailing list