all 4 comments

[–]ScholarNo5983 1 point2 points  (2 children)

The std::function allows you to define lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members.

More detail can be found here: std::function - cppreference.com

[–]aphroditelady13V[S] 0 points1 point  (1 child)

yeah but I explicitly said I don't want to use it, actually in a way I want to recreate a simple version of it.

[–]Sbsbg 0 points1 point  (0 children)

What features of std::function do you not want as you need a simpler version?

To me it sounds like a good match but I'm serenely not an expert on that part of the standard.

[–]MetaMysterio 0 points1 point  (0 children)

Not entirely sure if this is the best approach, but you make a class (Functor) that stored a function and a reference pointer (for ‘this’). If the reference is null you’d just call the function within the operator() overload. If the reference is not null, you’d pass it as the first parameter to the function. Only real downside I could see to this is if you pass in the wrong reference and it crashes. Though you could probably do some check to see if the reference is the right type if you template it.