why can't I call const methods on shared objects?

Vlad Levenfeld via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 9 16:56:25 PDT 2014


PS After reading your post I experimented with overloading 
shared/unshared methods in my code and came up with this solution:

shared Id!Service id ()() const if (is (typeof(this) == shared)) {
   return (cast(Service)this).id;
}
Id!Service id () const {
   return service_id;
}

I like this better than casting at the callsite (though it would 
be nice to roll those two into one method using a static if 
somehow, but I can't think of any way to do this).


More information about the Digitalmars-d-learn mailing list