Created
September 1, 2015 20:48
-
-
Save PIlin/7b0d22f72c60b78e874e to your computer and use it in GitHub Desktop.
crtp.cpp
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> | |
using namespace std; | |
template <typename T, typename U> | |
struct Base | |
{ | |
void TestBase(void* ptr) //__attribute__ ((noinline)) | |
{ | |
U& ref = *reinterpret_cast<U*>(ptr); | |
static_cast<T*>(this)->Test(ref); | |
} | |
}; | |
struct Child : public Base<Child, float> | |
{ | |
void Test(float& val) | |
{ | |
//cout << __FUNCTION__ << " = " << val << endl; | |
printf("%f", val); | |
} | |
}; | |
int main() { | |
Child c; | |
float x = 42.0f; | |
c.TestBase(&x); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment