求找错,跟书上一样,而且自查过后木有发现错误

是宝啊 2014-07-08 10:12:34



代码如下:
#include<iostream>
using namespace std;
enum CUP_Brand{Intel,AMD};
class CPU
{
private:
CPU_Brand brand;
int frequency;
float voltage;

public:
CPU(CPU_Brand bra,int fre,float vol)
{
brand=bra;
frequency=fre;
voltage=vol;
cout<<"构造函数执行"<<endl;
}
~CPU(){cout<<"析构函数执行"<<endl;}
void run(){cout<<"cpu start running"<<endl;}
void stop(){cout<<"cpu stop running"<<endl;}
};
void main()
{

CPU cpu(Intel,300,2.8);
cpu.run();
cpu.stop();
}

错误如下:
Compiling...
cpu类.cpp
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(7) : error C2146: syntax error : missing ';' before identifier 'brand'
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(7) : error C2501: 'CPU_Brand' : missing storage-class or type specifiers
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(7) : error C2501: 'brand' : missing storage-class or type specifiers
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(12) : error C2629: unexpected 'class CPU ('
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(12) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
D:\Program Files\Microsoft Visual Studio\Common\MSDev98\cpu类.cpp(26) : error C2661: 'CPU::CPU' : no overloaded function takes 3 parameters
执行 cl.exe 时出错.

cpu类.obj - 1 error(s), 0 warning(s)
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
是宝啊 2014-07-08
  • 打赏
  • 举报
回复
还能回复么,结贴早了,想问如果想想在结果中显示Intel 而不是枚举常量代表的序号值怎么办
#include<iostream>
using namespace std;
enum CPU_Brand{Intel,AMD};
class CPU
{
private:
	CPU_Brand brand;
	int frequency;
	float voltage;
	
public:
	CPU(CPU_Brand bra,int fre,float vol)
	{
		brand=bra;
		frequency=fre;
		voltage=vol;
		cout<<"构造函数执行"<<endl;
		cout<<"cpu型号:"<<brand<<"\t"<<frequency<<"\t"<<voltage<<endl;
	}
	~CPU(){cout<<"析构函数执行"<<endl;}
	void run(){cout<<"cpu start running"<<endl;}
	void stop(){cout<<"cpu stop running"<<endl;}
};
void main()
{ 

   CPU cpu(Intel,300,2.8);
   cpu.run();
   cpu.stop();
}
是宝啊 2014-07-08
  • 打赏
  • 举报
回复
额,,,,好吧,表示检查过名称,然后就,,,晃过去了
ztenv 版主 2014-07-08
  • 打赏
  • 举报
回复
唉,认真一点会检查不出来?
Pandorym 2014-07-08
  • 打赏
  • 举报
回复
enum CUP_Brand  //应该是 CPU_Brand 吧?
{Intel,
 AMD
};

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧