为什么这个不行呢,有关位域问题。
主要是switch语句出了问题, 只执行default语句了,不知道怎么回事,vc++6.0中。#include<iostream>using namespace std;
enum Sys {LOW, HIGH}; //系统位数
enum Core {ONE, TWO, FOUR};//cpu单,双,四核
enum Thread {YES, NO}; //是否支持多线程
class Cpu //Cpu类定义
{
public:
Cpu():frequ(0), system(LOW), core(ONE), thread(YES){}
Cpu(int fre, Sys sys, Core co, Thread th):frequ(fre), system(sys), core(co), thread(th){}
void show(void);
private:
unsigned int frequ : 12;
Sys system : 1;
Core core : 2;
Thread thread : 1;
};
void Cpu::show(void)
{
cout<<"the cpu information is:"<<endl;
cout<<"frequency(MHz):"<<frequ<<endl;
cout<<"the system is:"<<endl;
switch(system)
{
case LOW:
cout<<"32bit"<<endl;
break;
case HIGH:
cout<<"64bit"<<endl;
break;
default:
cout<<"information error!"<<endl;
}
cout<<"the core is"<<endl;
switch(core)
{
case ONE:
cout<<"single core"<<endl;
break;
case TWO:
cout<<"double cores"<<endl;
break;
case FOUR:
cout<<"double double cores"<<endl;
break;
default:
cout<<"information error!"<<endl;
}
cout<<"the cpu support over thread:"<<endl;
switch(thread)
{
case YES:
cout<<"yes"<<endl;
break;
case NO:
cout<<"no"<<endl;
break;
default:
cout<<"information error!"<<endl;
}
}
int main(void)
{
Cpu c(2000, HIGH, FOUR, NO);
c.show();
cout<<"the size of the class is:"<<sizeof(Cpu)<<endl;
return 0;
}