Created
May 12, 2014 09:38
-
-
Save ugovaretto/34711815f608ba1d7417 to your computer and use it in GitHub Desktop.
Base class initialization with variadic templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct B1 { | |
B1(int) {} | |
int Get() const { return 1; } | |
}; | |
struct B2 { | |
B2(int) {} | |
int Get() const { return 2; } | |
}; | |
template < typename...BasesT > | |
struct C : BasesT... { | |
C(const BasesT&...args) : BasesT(args)... {} | |
template < typename B > | |
int Get() const { return B::Get(); } | |
}; | |
int main(int, char**) { | |
C<B1, B2> c = { | |
{1},. | |
{2} | |
}; | |
std::cout << c.Get<B1>() << ' ' << c.Get<B2>() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment