C++类和对象
定义一个类
enum CPU_Rank {
P1=1,P2,P3,P4,P5,P6,P7};
class CPU{
private:
CPU_Rank rank;
int frequency;
float volage;
public:
CPU(CPU_Rank r,int f,float v);
~CPU();
void run();
void stop();
};
CPU::CPU(CPU_Rank r,int f,float v){
rank = r;
frequency = f;
volage = v;
}
void CPU::run(){
cout << "running" << endl;
cout << "rank : " << (CPU_Rank)rank << endl;
cout << "frequency : " << frequency << endl;
cout << "volage : " << volage << endl;
}
void CPU::stop(){
cout << "Execution of the program has stopped" << endl;
}
CPU::~CPU(){
cout << "destructor" << endl;
}
int main(){
CPU c(P1,3,1.33);
c.run();
c.stop();
return 0;
}
构造函数
#include<iostream>
using namespace std;
class CPU{
private: