January 2020
Intermediate to advanced
454 pages
11h 25m
English
Currently, our wrappers store an instance to each type. This approach is often used with type erasure, but in our case, it prevents the ability to create many delegates for the same object (that is, no support for one-to-many). To fix this, we will store a pointer to an object in our wrappers instead of the object itself, as follows:
template< typename T, typename RET, typename... ARGS >class wrapper : public base<RET, ARGS...>{ const T *m_t{}; RET (T::*m_func)(ARGS...);public: wrapper(const T *t, RET (T::*func)(ARGS...)) : m_t{t}, m_func{func} { } RET func(ARGS... args) override { return std::invoke(m_func, m_t, args...); }};
As shown in the preceding, the only change we have made is we store ...