| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 877 人关注过本帖
标题:关于结构体按地址传递给函数问题,,程序求纠错
只看楼主 加入收藏
此用户不存在
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-7-12
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:2 
关于结构体按地址传递给函数问题,,程序求纠错
#include<iostream>
using namespace std;
struct box{
  char maker[40];
  float height;
  float width ;
  float length;
  float volume;
};
void show(box);
float tiji(box*);
int main()
{
    box a={"shandong",3,3,3,0};
   
   
    cout<<"the tiji is "<<tiji[&a]<<endl;
    show(a);
 return 0;
}
void show(box a )
{
 cout<<"the maker is "<<a.maker<<endl;
 cout<<"the height is "<<a.height <<endl;
 cout<<"the width is  "<<a.width <<endl;
 cout<<"the length is "<<a.length <<endl;
 cout<<"the volume is"<<a.volume <<endl;
}
float tiji(box* pa)
{
   pa->volume =pa->height *pa->length *pa->width ;
   return pa->volume ;
}
搜索更多相关主题的帖子: include shandong return volume 结构体 
2016-01-31 10:59
此用户不存在
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-7-12
收藏
得分:0 
error C2107: 非法索引,不允许间接寻址
 cout<<"the tiji is "<<tiji[&a]<<endl;
这是运行不过去的地方  他说不允许间接寻址
2016-01-31 13:11
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:10 
函數用[],你哪看來的?雖然説C++對某些函數可以這樣寫,但卻不是你現在這種情形。

授人以渔,不授人以鱼。
2016-01-31 14:18
快速回复:关于结构体按地址传递给函数问题,,程序求纠错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019915 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved