C++ member function translations

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Sat Jul 28 02:23:27 PDT 2007


> And in response to Christian -- I would have expected 'const ref StBar'
> to be the way to translate 'const StBar&' from C++.  That doesn't work?

Well, I'm pretty sure that 'const ref StBar' is the same as 'ref
const(StBar)' for function arguments. And the reason why I think 'ref
const(StBar)' is not going to be a 'const StBar&' equivalent is:

---
struct StBar { int i; }

void foo(ref const(StBar) b) {
  b.i = 2; // this should be allowed...
}

void main() {
  StBar bar;
  bar.i = 1;

  foo(b);

  const(StBar) cbarcopy = bar;
  cbarcopy.i = 2; // ... because this is allowed
}
---

I.e. making a plain-data struct containing no references const doesn't
change its behaviour at all.

Christian


More information about the Digitalmars-d-learn mailing list