0からC++(五)匿名共同体を学ぶ
1115 ワード
#include <iostream>;
#include <cmath>;
#include <string>;
#include <cstring>;
/*
(anonymous union) , 。 ,
。
, , id_num id_char price , ,
id_val. 。
*/
struct widget{
char brand[20];
int type;
union {
long id_num;
char id_char[20];
};
};
int main(){
using namespace std;
widget price;
price.type = 1;
if(price.type == 1){
cin >> price.id_num;
}else{
cin >> price.id_char;
}
if(price.type == 1){
cout << price.id_num << endl;
}else{
cout << price.id_char << endl;
}
}