1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <string>
struct Class {};
struct A : virtual public Class {
int num;
A (int n) : num(n) {std::cout << "A::num = " << num << std::endl;}
};
struct B : virtual public Class {
int num;
double dub;
B (int n) : num(n) {std::cout << "B::num = " << num << std::endl;}
B (int n, double d) : num(n), dub(d) {std::cout << "B::num = " << num << ", dub = " << d << std::endl;}
};
struct C : virtual public Class {
int num;
std::string str;
C (int n) : num(n) {std::cout << "C::num = " << num << std::endl;}
C (int n, const std::string& s) : num(n), str(s) {std::cout << "C::num = " << num << ", str = " << str << std::endl;}
};
template <typename T> struct Base {};
template <> struct Base<A> : public A {using A::A;};
template <> struct Base<B> : public B {using B::B;};
template <> struct Base<C> : public C {using C::C;};
template <typename... T>
struct Multiclass : virtual public Base<T>... { // variadic base list, working as intended
Multiclass (int n) : Base<T>(n)... {} // variadic member initializer list, but useless in this case
template <typename... ARGS>
Multiclass (ARGS... args) {} // How to handle the general case??? Pack expansion of some sort?
};
int main() {
Multiclass<A,B,C> a(5); // This doesn't help much. How to get the lines below to work?
// Multiclass<A,B,C> b(1, 2, 4.1, 3, "Hi"); // Call up constructors of A, B, C.
// Multiclass<C,B,A> c(3, "Hi", 2, 4.1, 1); // Call up constructors of C, B, A.
// Multiclass<A,C> d(5, 3, "Hi"); // Call up constructors of A, C.
}
|