Bug 2058 – Describe hidden value passed to class member functions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-04-29T14:57:00Z
Last change time
2015-06-09T01:14:36Z
Assigned to
bugzilla
Creator
jlquinn
Comments
Comment #0 by jlquinn — 2008-04-29T14:57:28Z
As in C++, D appears to implicitly pass a reference to the class instance into a call to a member function to support references to class member vars and "this".
The fact that a hidden var is passed in is documented in reference to nested classes, but not for basic member functions.
This behavior is likely well known to experienced c++ developers, but needs to be documented in a language spec.
I ran into this trying to pass a class member function into std.algorithm.lowerBound, which of course doesn't work because of the hidden class reference. (There needs to be a way to pass a member function in easily - subject for another bug).
Comment #1 by bugzilla — 2008-04-29T15:00:12Z
Passing in a member function is easy - they pass as delegate types, rather than function pointer types.
Comment #2 by jlquinn — 2008-05-01T10:42:44Z
I eventually figured out how to use a delegate here. I had been working too hard at it.
At this point, I'm thinking the issue is that lowerBound is specified with "alias less", which doesn't really tell a newbie what is really safe to pass in. Some more detailed docs with basic examples would help, both using standalone functions, and delegates. This is really more a meta issue for stuff in algorithms and other places that can take function references of various forms.