|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.bugs - [Issue 2058] New: Describe hidden value passed to class member functions
http://d.puremagic.com/issues/show_bug.cgi?id=2058 Summary: Describe hidden value passed to class member functions Product: D Version: 2.012 Platform: PC URL: http://www.digitalmars.com/d/2.0/class.html OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: www.digitalmars.com AssignedTo: bugzilla digitalmars.com ReportedBy: jlquinn us.ibm.com 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). -- Apr 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2058 ------- Comment #1 from bugzilla digitalmars.com 2008-04-29 15:00 ------- Passing in a member function is easy - they pass as delegate types, rather than function pointer types. -- Apr 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2058 ------- Comment #2 from jlquinn us.ibm.com 2008-05-01 10:42 ------- 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. -- May 01 2008
|