关于c++中枚举问题,求解!
#include<iostream>usingnamespacestd;enumNeucleus{A,B,C};enumWordLong{AB,BC};enumThrea...
#include<iostream>
using namespace std;
enum Neucleus{A,B,C};
enum WordLong{AB,BC};
enum Thread{Yes,No};
class CPU{
public:
CPU(unsigned clock,Neucleus nuecleus,WordLong wordlong,Thread thread):clock(clock),neucleus(neucleus),wordlong(wordlong),thread(thread){}
~CPU(){}
void show();
private:
unsigned clock:12;
Neucleus neucleus:2;
WordLong wordlong:1;
Thread thread:1;
};
void CPU::show(){
cout<<"时钟频率:"<<clock<<endl;
switch(neucleus){
case A:cout<<"单核";
break;
case B:cout<<"双核";
break;
case C:cout<<"四核";
break;
}
cout<<endl;
switch(wordlong){
case AB:cout<<"32位";
break;
case BC:cout<<"64位";
break;
}
cout<<endl;
switch(thread){
case Yes:cout<<"Yes";
break;
case No:cout<<"No";
break;
}
cout<<endl;
}
int main(void){
CPU china(3000,C,BC,Yes);
china.show();
cout<<sizeof(CPU)<<endl;
return 0;
}
运行结果与原设想的结果不一样,求解释,并修改下程序输出正确答案!灰常感谢!
我想了很久都想不明白,求前辈指教! 展开
using namespace std;
enum Neucleus{A,B,C};
enum WordLong{AB,BC};
enum Thread{Yes,No};
class CPU{
public:
CPU(unsigned clock,Neucleus nuecleus,WordLong wordlong,Thread thread):clock(clock),neucleus(neucleus),wordlong(wordlong),thread(thread){}
~CPU(){}
void show();
private:
unsigned clock:12;
Neucleus neucleus:2;
WordLong wordlong:1;
Thread thread:1;
};
void CPU::show(){
cout<<"时钟频率:"<<clock<<endl;
switch(neucleus){
case A:cout<<"单核";
break;
case B:cout<<"双核";
break;
case C:cout<<"四核";
break;
}
cout<<endl;
switch(wordlong){
case AB:cout<<"32位";
break;
case BC:cout<<"64位";
break;
}
cout<<endl;
switch(thread){
case Yes:cout<<"Yes";
break;
case No:cout<<"No";
break;
}
cout<<endl;
}
int main(void){
CPU china(3000,C,BC,Yes);
china.show();
cout<<sizeof(CPU)<<endl;
return 0;
}
运行结果与原设想的结果不一样,求解释,并修改下程序输出正确答案!灰常感谢!
我想了很久都想不明白,求前辈指教! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询