Skip to content

Instantly share code, notes, and snippets.

@turugina
Created October 7, 2010 06:53
Show Gist options
  • Save turugina/614681 to your computer and use it in GitHub Desktop.
Save turugina/614681 to your computer and use it in GitHub Desktop.
#include <iostream>
template<typename D>
struct Hige
{
void hige() { static_cast<D*>(this)->doit(); } // <- **
};
class Hoge
: Hige<Hoge>
{
friend class Hige<Hoge>;
void doit() { std::cout << "hoge\n"; }
public:
void hige() { Hige<Hoge>::hige(); }
};
class Hage
: Hige<Hage>
{
friend class Hige<Hage>;
void doit() { std::cout << "hage\n"; }
public:
void hige() { Hige<Hage>::hige(); }
};
class FooBar
: Hoge, Hage
{
public:
void hoge() { Hoge::hige(); }
void hage() { Hage::hige(); }
};
int main()
{
FooBar fb;
fb.hoge();
fb.hage();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment