错误提示collect2: error: ld returned 1 exit status怎么解决

sevendays 2012-11-17 09:23:56
本人做了一个课后练习题 代码如下 编译的时候出现
[jli52@1005-20 chap_7]$ g++ -g struMeth.cpp -o struMeth
/tmp/ccNELBUx.o: In function `main':
/home/122/j/jli52/Documents/chap_7/struMeth.cpp:51: undefined reference to `calculate(box*)'
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
哪位大神能给解答一下 谢谢啦
还有一个问题 有个练习题 不太明白 有个结构candyBar 包含三个成员 分别是 名称 重量 和卡路里 要求用new来动态分配数组 而不是声明一个包含三个元素的candyBar数组 我不明白的是 如果是用数组的话 数组只能储存同一个类型的数据 但是这个结构中的数据类型是不同的 如何用数组去储存这些数据



#include<iostream>
#include<cmath>


struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};


const void show(box info);
box calculate (box *info);




const void show(box info,box info1)
{
using namespace std;
cout<<"The maker of the box is: "<<info1.maker<<endl;
cout<<"The height of the box is: "<<info1.height<<endl;
cout<<"The length of the box is: "<<info1.length<<endl;
cout<<"The volume of the box is: "<<info.volume<<endl;

}


box caculate (box *info)
{
box result;
result.volume=info->height*info->length*info->width;
return result;
}


int main()
{
using namespace std;
box info;
box result;
cout<<"Please enter the maker, height, width, and length of the box respectly"
<<endl;
cin.getline(info.maker,40);
cin>>info.height;
cin>>info.width;
cin>>info.length;
result=calculate(&info);
show(result,info);
return 0;
}



...全文
21958 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sevendays 2012-11-17
  • 打赏
  • 举报
回复
嗯 我刚才也发现这个了 谢谢啦
JiMoKuangXiangQu 2012-11-17
  • 打赏
  • 举报
回复
box caculate (box *info) -> box calculate (box *info)

33,321

社区成员

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

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