D2.0 const this methods

Bill Baxter dnewsgroup at billbaxter.com
Mon Jun 18 00:58:15 PDT 2007


 From the const page docs
class Foo {
    invariant int foo() {
       ...
    }
}

makes 'this' and the return value invariant.

But it give a syntax example for const methods.  So is it just 'const' 
instead of 'invariant'?

class Foo {
    const int foo() {
       this.value = 10; // error -- this is const
       return this.value;
    }
}

So what if I want to make a method that returns a const ptr/ref but 
modifies 'this'?

--bb



More information about the Digitalmars-d mailing list