使用结构体函数

来源:互联网 发布:淘宝助理一键适配 编辑:程序博客网 时间:2024/05/17 22:39

在c语言中涉及坐标点的运算,使用结构体远比c++重新定义一个坐标类简单易操作。

struct Point{doule x,y;};

double dist(struct Point a,struct Point b)

{

return  fuc(a.x-b.x,a.y-b.y);

}

不过这样用起来还是挺麻烦的要在每个形参前加上struct,现在有一个方法可以避开这种重复;

typedef strcut{double x,y;}Point;

double dist(Point a,Pointb)

{

return  fuc(a.x-b.x,a.y-b.y);

}

0 0