opAssign() still accepted for classes???

KennyTM~ kennytm at gmail.com
Fri Apr 29 11:46:33 PDT 2011


On Apr 30, 11 01:54, Steven Schveighoffer wrote:
> On Fri, 29 Apr 2011 13:49:19 -0400, KennyTM~ <kennytm at gmail.com> wrote:
>
>> Though this isn't valid with a 'struct'.
>>
>> ------------------------
>> import std.stdio;
>> struct K {
>> K opAssign(int x) {
>> writeln(x);
>> return this;
>> }
>> }
>> void main() {
>> // K k = 8; // Error: cannot implicitly convert expression (8) of type
>> int to K
>> K k;
>> k = 8; // OK.
>> }
>> ------------------------
>
> Interesting! So this is definitely an inconsistency that indicates the
> class version is a bug.
>
> -Steve

Turns out it is an old bug.

http://d.puremagic.com/issues/show_bug.cgi?id=671


More information about the Digitalmars-d mailing list