Implicit const

Bill Baxter dnewsgroup at billbaxter.com
Wed Apr 2 18:42:44 PDT 2008


One of the more annoying things about C++ (and current D2) is that calls 
to functions fail to compile if the designer hasn't given const much 
thought.  Example:

class Class {
    int getA() { return a_; }
private:
    int a_;
}

getA could easily be made
     int getA() const { return a_; }
but the class writer just didn't think of it.

However, when the compiler compiles getA, it can actually tell pretty 
easily, that, yeh, getA is really also OK as const.  So at least for 
such simple cases, it seems that the explicit labeling is not really 
necessary.  Maybe the set of cases where it would work is large enough 
to make this a useful feature.

--bb



More information about the Digitalmars-d mailing list