您的位置:首页 > 其它

结构体和函数

2014-02-24 17:30 155 查看
结构体和函数
结构体是一种数据类型,作为数据类型,它就可以定义变量,同时也可以作为函数的形式参数,或者让函数的返回值为一个结构体类型。下面通过一个代码来说明这一点:
#include <iostream>
using namespace std;
struct people

{
int weight;
int tall;
bool sex;
int age;
};
const int class=60;
people &sum(people1,people2);
void show(people);
int main()
{
people a=(80,190,1,19);
people b=(90,200,1,21);
people *number=&total(a,b);
cout<<"两人总计为:"<<endl;
show(*number);
delete number;
return 0;
}
people &sum(people t1,people t2)
{
people *total=new people;
total->tall=t1.tall+t2.tall;
total->weight=t1.weight+t2.weight;
return *total;
}
void show(people t3)
{
cout<<t3.tall<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: