【C++入门】使用code blocks,新建工程,和vc++输入一样的代码,vc++可以运行,code blocks显示undefined reference

SichengT 2017-11-09 09:25:42
所有的代码如下:
file1.cpp //主体
#include <iostream>
#include "arraymax.h" //为什么这么操作呢?
using namespace std;

int main()
{
arraymax arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
return 0;
}
arraymax.h//对类的定义
#include <iostream>
#include "arraymax.h" //为什么这么操作呢?
using namespace std;

int main()
{
arraymax arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
return 0;
}
arraymax.cpp//定义函数
#include<iostream>
#include"arraymax.h"
using namespace std;

void arraymax::set_value()
{
int i;
for(i=0;i<10;i++)
cin>>array[i];
}

void arraymax::max_value()
{
int i;
max = array[0];
for(i=1;i<10;i++)
if(array[i]>max)max=array[i];
}
void arraymax::show_value()
{
cout<<"max="<<max;
}
...全文
319 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SichengT 2017-11-20
  • 打赏
  • 举报
回复
找到原因了: 应该是使用错误, 在新建类的时候用错了,并不是代码的问题。 谢谢各位。
热血打工人 2017-11-11
  • 打赏
  • 举报
回复
当你自己开发"arraymax.h"时,需要include一下
大米粥哥哥 2017-11-10
  • 打赏
  • 举报
回复
.h文件的代码呢 少了声明?
jiht594 2017-11-10
  • 打赏
  • 举报
回复
引用 2 楼 hefashion0190 的回复:
可能是.h文件的代码少了声明。

为什么都喜欢code blocks编译器? 感觉和vc6差不多。

Windows下可以使用Visual Studio 2015/2017社区免费版 或者 eclipse呀! 这些不挺好呀!

体积小,速度快
FoolCarpe 2017-11-10
  • 打赏
  • 举报
回复
可能是.h文件的代码少了声明。 为什么都喜欢code blocks编译器? 感觉和vc6差不多。 Windows下可以使用Visual Studio 2015/2017社区免费版 或者 eclipse呀! 这些不挺好呀!

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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