Created
August 13, 2014 14:59
-
-
Save mpenick/2a5ba757de92edb3020e 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
template<typename From, typename To> | |
To alias_cast(From from) | |
{ | |
struct AliasType | |
{ | |
union | |
{ | |
From from; | |
To to; | |
}; | |
}; | |
AliasType alias; | |
alias.from = from; | |
return alias.to; | |
} | |
int main() | |
{ | |
int* i = new int; | |
char* c = alias_cast<int*, char*>(i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment