Conflicting types and previous declaration of x was here…what?

风格不统一 提交于 2019-12-04 05:07:42

Any of them that say there was an 'implicit' definition: this can be solved by pre-declaring it. As an example, you pre-declared float trapezoid and int trapezoid, but you didn't pre-declare trapezoid_area. As others pointed out, you also can't overload in C as you can in C++.

In a few areas you're trying to do implicit multiplication -- eg, PI(pow(r,2)) should be PI * (pow(r,2)).

The errors you're seeing are because you're defining the same function twice with different signatures

float trapezoid(float b1, float b2, float h);
int trapezoid();

Based on your other definitions it looks like the first trapezoid functions should be named trapezoid_volume

float trapezoid_volume(float b1, float b2, float h);
int trapezoid();

C does not support function overloading. C++ does.

And since you accidentally declared trapezoid_volume as trapezoid, you get a compiler error.

you defined twice function trapezoid. C isn't C++. You can't define the same function with different signatures like you do in C++ using overloading features.

#define PI 3.141

float trapezoid(float b1, float b2, float h);
int trapezoid();

I think you want

float trapezoid_volume(...);
/*             ^^^^^^^                 */

To answer your question about defining PI - pi is usually defined in math.h (as M_PI), but since it's not part fo the actual standard you might need to do some configuration to get it.

For example, when using MSVC you need to define _USE_MATH_DEFINES to get it. See

If your platform doesn't have it, you might want to throw something like the following into a header:

#ifndef
#define M_PI 3.14159265358979323846264338327
#endif
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!