Created
September 11, 2014 06:59
-
-
Save wackoisgod/93a903a87a00082e1834 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 "stdafx.h" | |
class PrivateClass{ | |
private: | |
void SomeFunction() { printf("Hello World"); }; | |
}; | |
template <class Tag> | |
struct touch | |
{ | |
static typename Tag::type value; | |
}; | |
template <class Tag> | |
typename Tag::type touch<Tag>::value; | |
template <class Tag, typename Tag::type x> | |
struct touch_private | |
{ | |
touch_private() { touch<Tag>::value = x; } | |
static touch_private instance; | |
}; | |
template <class Tag, typename Tag::type x> | |
touch_private<Tag, x> touch_private<Tag, x>::instance; | |
struct AS { typedef void(PrivateClass::*type)(); }; | |
template struct touch_private < AS, &PrivateClass::SomeFunction >; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
PrivateClass c; | |
(c.*touch<AS>::value)(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let me get this correctly:
touch_private
.touch_private::instance
gets created on line 24.PrivateClass::SomeFunction
gets assigned to the static membertouch<AS>::value
which is of type pointer to member of PrivateClass that takes no parameters and returns void.main
.Does this all have any practical application or is it just for fun? 😃