Skip to content

Instantly share code, notes, and snippets.

@ugovaretto
Created May 12, 2014 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugovaretto/34711815f608ba1d7417 to your computer and use it in GitHub Desktop.
Save ugovaretto/34711815f608ba1d7417 to your computer and use it in GitHub Desktop.
Base class initialization with variadic templates
#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