Bug 2495 – const syntax for member functions needs better description
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-12-06T13:23:00Z
Last change time
2015-06-09T01:20:44Z
Keywords
spec
Assigned to
nobody
Creator
jlquinn
Comments
Comment #0 by jlquinn — 2008-12-06T13:23:58Z
The syntax for declaring const member functions is not very clear. There is no grammar. You need to infer from various examples what to do. For instance:
class B {}
class A {
B x;
const B getB() { return B; }
}
doesn't compile, because this is a const function returning a nonconst value. I had to find the answer on a forum. It's challenging to figure this out from the docs:
class B {}
class A {
B x;
const const(B) getB() { return B; }
}
Examples covering more use cases would probably help, as well as more formally describing how const is specified. Perhaps modifying the example of an invariant member function to return a value (other than string) would help.
Comment #1 by github-bugzilla — 2012-01-22T20:53:31Z