On Apr 30, 11 01:54, Steven Schveighoffer wrote:
On Fri, 29 Apr 2011 13:49:19 -0400, KennyTM~ <kenn...@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
That said, for a 'struct' the 'Type var = expr;' declaration is expected
to call the constructor:
---------------------
import std.stdio;
struct K {
this(int x) {
writeln(x);
}
}
void main() {
K k = 8;
}
---------------------