/*lab7_2声明一个CPU类,包含主频(c),字长(wordlength),CPU倍频系数() 等属性。有两个公有成员函数run,stop。其中字长
(wordlength),为枚举型enum cpu_fre={ W16, W32, W64, W128, W256}; frequency为单位是GHz的实数类型, coefficient为实数型的值。
说明并实现这个类,观察构造函数和析构函数的调用顺序。*/
# include <iostream>
using namespace std;
enum word_length{w16,w32,w64,w128,w256};
class CPU{
public:
CPU(float frequency, word_length wordlength,float coefficient);
void run();
void show(){
cout<<"主频(frequency):"<<frequency<<endl;
cout<<"字长(wordlength):";
switch(wordlength){
case 1:cout<<"W16"<<endl;break;
case 2:cout<<"W32"<<endl;break;
case 3:cout<<"W64"<<endl;break;
case 4:cout<<"W128"<<endl;break;
case 5:cout<<"W256"<<endl;break;
};
void stop();
private:
float frequency;
enum wordlength;
float coefficient;
};
CPU::CPU(float frequency, word_length wordlength,float coefficient){
cout<<"构造函数!"<<endl;
}
void CPU::run(){
cout<<"函数运行"<<endl;}
void CPU::stop(){
cout<<"运行结束"<<endl;}
void main(){
CPU p1;p1.run();p1.show();p1.stop();
}
为什么错了? error C2535: '__thiscall CPU::CPU(float,enum word_length,float)' : member function already defined or declared
(wordlength),为枚举型enum cpu_fre={ W16, W32, W64, W128, W256}; frequency为单位是GHz的实数类型, coefficient为实数型的值。
说明并实现这个类,观察构造函数和析构函数的调用顺序。*/
# include <iostream>
using namespace std;
enum word_length{w16,w32,w64,w128,w256};
class CPU{
public:
CPU(float frequency, word_length wordlength,float coefficient);
void run();
void show(){
cout<<"主频(frequency):"<<frequency<<endl;
cout<<"字长(wordlength):";
switch(wordlength){
case 1:cout<<"W16"<<endl;break;
case 2:cout<<"W32"<<endl;break;
case 3:cout<<"W64"<<endl;break;
case 4:cout<<"W128"<<endl;break;
case 5:cout<<"W256"<<endl;break;
};
void stop();
private:
float frequency;
enum wordlength;
float coefficient;
};
CPU::CPU(float frequency, word_length wordlength,float coefficient){
cout<<"构造函数!"<<endl;
}
void CPU::run(){
cout<<"函数运行"<<endl;}
void CPU::stop(){
cout<<"运行结束"<<endl;}
void main(){
CPU p1;p1.run();p1.show();p1.stop();
}
为什么错了? error C2535: '__thiscall CPU::CPU(float,enum word_length,float)' : member function already defined or declared
