Created
October 7, 2010 06:53
-
-
Save turugina/614681 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
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