why ; ?
Nick Sabalausky
a at a.a
Thu May 8 14:03:33 PDT 2008
"Michael Neumann" <mneumann at ntecs.de> wrote in message
news:48236605.9050806 at ntecs.de...
> Yeah, you are right. It is inconsitent to define the instance variable
> with "i" while accessing it with "@i":
>
> class A {
> int i;
>
> void foo(int i) { @i = i; }
> };
>
That's not really what I meant (See below for clarification of what I
meant). Actually, I hadn't even thought of that, but it is a good point.
> Btw, I wrote a C++ preprocessor script that during compilation
> transparently replaces every occurence of "@" by "this->".
> Would be nice to have this build into D directly.
>
I agree, that would be nice (provided, of course, it didn't interfere with
deliberate uses of "@", such as within a string). Unfortunately, in C++ or D
it still wouldn't solve the problem of accidentially clobbering the instance
variable "i" by intending trying to use a local var "i", but forgetting to
declare it:
// Note: untested
class A {
int i=0;
void foo() {
// Accidentially clobbers "this.i" aka "@i"
for(i=0; i<77; i++)
{/* Do stuff */}
}
invariant() {
assert(this.i==0); // Fails after foo() is called
}
}
I still like the @ thing, though.
More information about the Digitalmars-d
mailing list