const Propagation

Julian Kranz via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 29 07:50:43 PST 2014


No, actually I don't at all understand why the function does not 
need to be const any longer since this code does not compile:

import std.stdio;

class Hugo {
   public int x = 42;

   void blah(this T)(void function(const Hugo h) f) {
     f(this);
   }
}

void main() {
     Hugo hugo = new Hugo();

     const Hugo inge = hugo;
     void function(const Hugo h) g = function(const Hugo h) {
       write("foobar ");
       writeln(h.x);
     };
     inge.blah(g);
}

Sorry guys, I know I'm a bloody D beginner, ...


More information about the Digitalmars-d mailing list