c++ 枚举类型如何使用?
#include"iostream"usingnamespacestd;classCPU{public:CPU(inta,intb,doublec);CPU(CPU&am...
#include "iostream"using namespace std;class CPU{public: CPU(int a,int b,double c); CPU(CPU &); int getfr(){return frequency;} int getwo(){return wordlength;} double getco(){return coefficient;} void run(){cout<<"run"<<endl;} void stop(){cout<<"stop"<<endl;}private: int frequency; enum cpu_len {8,16,32,64,128,256}wordlength; double coefficient;};CPU::CPU(int a,int b,double c){ frequency=a; wordlength=b; coefficient=c; cout<<"构造函数被调用"<<endl;}CPU::CPU(CPU &L):frequency(L.frequency),wordlength(L.wordlength),coefficient(L.coefficient){ cout<<"拷贝构造函数被调用"<<endl;}int main(){ CPU cpu1(4,1,4.0); CPU cpu2(cpu1); cout<<"cpu1"<<endl; cout<<"主频:"<<cpu1.getfr()<<"MHz"<<"字长:"<<cpu1.getwo()<<"倍频:"<<cpu1.getco()<<endl; cout<<"cpu2"<<endl; cout<<"主频:"<<cpu2.getfr()<<"MHz"<<"字长:"<<cpu2.getwo()<<"倍频:"<<cpu2.getco()<<endl;}
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询