opAssign and const?
Era Scarecrow
rtcvb32 at yahoo.com
Thu May 3 22:49:29 PDT 2012
I have the following dilemma. Hopefully I have this right.
struct X {
ref X opAssign(X x2);
ref X opAssign(ref X x2);
}
X fn();
void func(){
X x, x2;
x = x2; //uses ref
x = fn(); //without ref
}
According to the book, this is how it is suppose to be. const is
a added promise not to modify anything. So... if i changed the
ref to ref const... it won't call unless the item input was const
as well.
//same as above except..
struct X {
ref X opAssign(X x2);
ref X opAssign(ref const X x2); //const added
}
void func(){
X x, x2;
const X x3;
x = x2; //without ref???
x = x3; //ref
}
Since the input is intended to be read only anyways, why won't
it work as expected with x = x2? This seems like a bug. If it's
not, then I need to make two ref versions so it will behave
properly. (If you need I can past actual working example)
More information about the Digitalmars-d-learn
mailing list