Ouch: return values as lvalue

Lionello Lunesu lio at lunesu.remove.com
Tue Jan 30 01:30:05 PST 2007


Consider this home-made const:

struct Task {
   char[] ID;
}
private Task _CurrentTask; //mutable
public Task CurrentTask() { return _CurrentTask; } //const

public void StopTask() {
   CurrentTask.ID = null;
}

Notice the bug? That last line should read "_CurrentTask.ID = null;"

Isn't there something the compiler can do to help me catch these bugs?

L.



More information about the Digitalmars-d mailing list