Consider this template
function, invoking a method of an object of class T
.
template<class T, void (T::*Method)()>
void circuitousInvoke(T* callee) {
(callee->*Method)();
}
Example:
struct A {
void test() {};
}
circuitousInvoke<A, &A::test>(new A);
As the type T is already known to circuitousInvoke from parameter callee
, is there a way to avoid typing this type?
circuitousInvoke<&A::test>(new A);
This question refers to template functions only. Inheritance and other class based solutions are not suitable in this case. (In my project using a wrapper object would be more worse than typing an additional name.)
It would be possible in C++17 with auto
template<auto Method, typename T>
void circuitousInvoke(T* callee) {
(callee->*Method)();
}
and then
A a;
circuitousInvoke<&A::test>(&a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With