Mega Code Archive

 
Categories / C++ / Class
 

Unions and Classes are Related

#include <iostream>   using namespace std; union u_type {     u_type(int a);  // public by default     void showchars(void);     int i;     char ch[2];   };         u_type::u_type(int a)   {     i = a;   }         void u_type::showchars(void)   {     cout << ch[0] << " ";     cout << ch[1] << "\n";   }         main(void)   {     u_type u(1000);           u.showchars();           return 0;   }