URGENT
Urgent
can anyone give me a pratical example where unions can be used to
avoid C++ type checking ?
I don't know if that could be done quickly but I can show you how a Union causes multiple variables to point to the same address.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void pause()
{
std::cin.sync();
char c = getchar();
std::cin.sync();
}
union dont_do_this {
int a;
char b;
};
int main(int argc, char *argv[])
{
dont_do_this A;
A.a = 1;
int B = 1;
char C = (int) B; //Same As Type Casting
std::cout << A.b << '\n' << C;
pause();
return 0;
}
|
Do you have a specific thing you are trying to work around? I could help you with a more direct question.
Last edited on
Topic archived. No new replies allowed.