struct throws errors if it has a DTor
Namespace
rswhite4 at googlemail.com
Sat Dec 8 06:18:49 PST 2012
On Saturday, 8 December 2012 at 13:09:39 UTC, Maxim Fomin wrote:
> On Saturday, 8 December 2012 at 11:10:27 UTC, Namespace wrote:
>> Why this code compiles without Dtor, but not when I have one?
>>
>> http://dpaste.dzfl.pl/2792b974
>
> Reading compiler errors is a good idea:
>
> (18-25):Error: function c739.Color.opAssign (Color p) is not
> callable using argument types (Color) const
>
> Because you use didn't supply opAssign, default one is
> generated. It calls postblit and destructor for temporary. Once
> you define any of them, default opAssign cannot be const and
> because you assign static const structs in static constructor
> at lines 18-25, compiler issues errors.
>
> Solution is to move initialization of static fields to compile
> time and use static struct initialization. In any case you know
> values of Black, Green, etc. so why would one initialize them
> at runtime? You can also turn them into enums.
>
> http://dpaste.dzfl.pl/09572204
I have read the error messages, but they have made no sense to
me. It just seemed to be one of many bugs of D. But now it's
clear. Thank you. ;)
More information about the Digitalmars-d-learn
mailing list