main()问题

yxdxcy 2009-01-10 11:42:22
#include<iostream.h>
using namespace std;;
class Test{
private:
int num;

public:
Test(){
cout<<"Initializing default"<<endl;
num=0;
};
Test(int n){
cout<<"Initializing"<<n<<endl;
num=n;
};
}


int main()
{
Test x;
Test y(15);
Test array[2]={5,7};

}


编译时出现以下问题:

E:\make\Test:20: error: new types may not be defined in a return type
E:\make\Test:20: error: extraneous `int' ignored
E:\make\Test:20: error: `main' must return `int'
E:\make\Test:20: warning: return type for `main' changed to `int'
E:\make\Test: In function `int main(...)':
E:\make\Test:23: warning: unused variable 'array'

请问犯了什么错误,该怎么改正呢?
我改成void main(),或者不用返回类型也没有用,老是报错,我头都大了,入门真难啊?
...全文
93 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbh2001 2009-01-10
  • 打赏
  • 举报
回复
我在一楼的代码没有这个警告,有初始化应该不会
sinosinux 2009-01-10
  • 打赏
  • 举报
回复
不用去掉,说array没有被使用,没问题
yxdxcy 2009-01-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lbh2001 的回复:]
你的类定义后面少了分号结束
[/Quote]
正解.
再小声的问一下:warning: unused variable 'array'
这个警告怎么处理.
lpcii 2009-01-10
  • 打赏
  • 举报
回复
跟你改好了
#include <iostream>		//不要用#include<iostream.h>

using namespace std; //你多了个';'

class Test
{
private:
int num;

public:
Test(){
cout << "Initializing default" <<endl;
num=0;
};
Test(int n){
cout << "Initializing" << n <<endl;
num=n;
};
}; //少了个';'


int main()
{
Test x;
Test y(15);
Test array[2]={5,7};

return 0;
}
Leejun527 2009-01-10
  • 打赏
  • 举报
回复

#include <iostream.h>
using namespace std;;
class Test
{
private:
int num;

public:
Test(){
cout <<"Initializing default" <<endl;
num=0;
}
Test(int n){
cout <<"Initializing" <<n <<endl;
num=n;
}
};


int main()
{
Test x;
Test y(15);
Test array[2]={5,7};
return 0;
}
lbh2001 2009-01-10
  • 打赏
  • 举报
回复
你的类定义后面少了分号结束
lbh2001 2009-01-10
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
class Test
{
private:
int num;

public:
Test()
{
cout << "Initializing default " << endl;
num = 0;
};
Test(int n)
{
cout << "Initializing " << n <<endl;
num = n;
};
};


int main(void)
{
Test x;
Test y(15);
Test array[2] = {5 ,7};

return 0;
}

65,211

社区成员

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

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