const and non-const member function

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Wed Jul 25 08:14:45 PDT 2007


> In C++ it is possible to have a const and a non-const member function with
> the same name and parameter types. 
> ...
> Is something like this possible in D?

I don't think it's possible (yet). Trying

class Foo
{
  void bar() {}
  const void bar() {}
}

gives me an error. I'm not sure if it is by design or just not working yet.

> Furthermore, is it possible to overload opApply(...) so it can be called
> on non-const objects and const objects, and the non-const variant has
> read-write access:

Having that would pretty much depend on being able to have a opApply and a
const opApply. I tried by using two functions with different names, but the
compiler segfaulted on a ref const(Struct*).

Cheers,
Christian


More information about the Digitalmars-d-learn mailing list