[求助]能解释下这个程序吗?
struct widght{
char brand[20];
int type;
union
{
long id_num;
char id_char[20];
};
};
widght prize;
if(prize.type==1)
cin>>prize.id_num;
else
cin>>prize.id_char;
能解释下这个程序吗?
请各位大哥指点!!
类和结构很相似,类默认为private,而struct默认为public
class widght
{
public:
char brand[20];
int type;
union
{
long id_num;
char id_char[20];
};
};
widght prize;
if(prize.type==1) //"."为成员操作符,通过它可以访问类里的成员
cin>>prize.id_num;
else
cin>>prize.id_char;