[Issue 9665] Structure constant members can not be initialized if have opAssign
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 9 09:32:57 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9665
rswhite4 at googlemail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rswhite4 at googlemail.com
--- Comment #5 from rswhite4 at googlemail.com 2013-03-09 09:32:56 PST ---
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > This is unfixable problem, if I'm not mistaken.
> >
> > What if opAssign is const/inout?
>
> It would be invoked, but you cannot do any meaningful operation in it.
You can:
import std.stdio;
import std.c.string : memcpy;
struct Foo1 // opAssign is a function
{
int value;
void opAssign(int src) const {
int* ptr = cast(int*) &this.value;
*ptr = src;
}
}
struct Boo
{
const Foo1 f1;
this(int src)
{
f1 = src; // Error!
}
}
void main() {
Boo b = Boo(42);
writeln(b.f1.value); // prints 42
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list