Is there a simple way to do this in C++11? I'd like to keep both the multiple inheritance AND ability to cycle thru all the static functions in the pack, if possible.
#include <cstdio>
struct A { static void foo() {printf("fA\n");} static void bar() {printf("bA\n");} };
struct B { static void foo() {printf("fB\n");} static void bar() {printf("bB\n");} };
struct C { static void foo() {printf("fC\n");} static void bar() {printf("bC\n");} };
template <typename... T>
struct Z : public T... {
static void callFoos() {
/* ???? WHAT'S THE SYNTAX
T...::foo();
T::foo()...;
*/
}
static void callBars() {
/* ???? WHAT'S THE SYNTAX
T...::bar();
T::bar()...;
*/
}
};
int main() {
Z<A, B, C>::callFoos();
Z<A, B>::callBars();
}
Add a set of dispatcher function overloads:
void foo_caller() { }
template <typename T, typename ...Args>
void foo_caller()
{
T::foo();
foo_caller<Args...>();
}
Then use inside callFoos()
:
foo_caller<T...>();
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