Problem overloading operator for a struct with an immutable member

Nicolas Sicard via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 24 09:49:01 PDT 2015


I don't know if this is a bug or expected behaviour. The struct 
is mutable, assignable and pre-increment operator works. But 
post-increment doesn't compile because of the immutable member.

--
struct S
{
     int i;
     immutable(Object) o;

     S opUnary(string op)() { return this; }
     void opAssign(S other) {}
}

void main()
{
     S s, t;

     t = s; // OK
     ++s; // OK
     s++; // Error: cannot modify struct s S with immutable members
}
---


More information about the Digitalmars-d-learn mailing list