Functor reference through a std::function
You want to use the std::ref
template function to create a reference wrapper for your instance:
std::reference_wrapper
is a class template that wraps a reference in a copyable, assignable object.Function templates
ref
andcref
are helper functions that generate an object of typestd::reference_wrapper
, using template argument deduction to determine the template argument of the result.
You would use it like this:
t.add(std::ref(t));