Implicit conversion between structs?
Steve Teale
steve.teale at britseyeview.com
Mon Oct 31 10:39:57 PDT 2011
On Mon, 31 Oct 2011 07:58:11 -0500, Andrei Alexandrescu wrote:
> On 10/31/11 4:43 AM, Steve Teale wrote:
>> Is there a way to do this. For example if I have
>>
>> struct A { int a, b, c; }
>> struct B
>> {
>> int p, q, r, s;
>> this(A a) { p = a.a; q = a.b; r = a.c; }
>> }
>>
>> A a;
>> B b;
>> b = a;
>
> Use opAssign?
>
Joseph (aka Andrei),
But if B is not mine to mess with?
The two structs have a common type prefix. and D guarantees that there
are predictable values for the remainder of the larger one, so the
compiler could presumably figure it out. (Easy for me to say)
Steve
More information about the Digitalmars-d
mailing list