3 ms·
Or you can pass a reference to some object's method.
by golergka 10y ago
Or you can pass a reference to some object's method.
- Animats 10y agoIf that's supported in the language, yes. C++ supports this, but the syntax is special.[1] What's passed is not just a pointer to a function; it's really two pointers, one for the function and one with the "this" pointer. [1] http://umich.edu/~eecs381/handouts/Pointers_to_memberfuncs.pdf http://umich.edu/~eecs381/handouts/Pointers_to_memberfuncs.p...
- gpderetta 10y agonote that, in C++, pointers to member functions do not close over 'this' [1], so they are not really a reference to a method of an object, i.e. you need to provide the actual object externally to invoke the pmf. The closure need to be created explicitly with something like std::bind or an actual lambda, and passed around as an std::function (a type erased, generic closure wrapper) or as a template parameter. /pedantic [1] GCC does have a very old extension that actually creates the closure.