Incompatible types when assigning to type - C [closed]

青春壹個敷衍的年華 提交于 2019-12-13 06:59:18

问题


I'm working in Code::Blocks on a project in C.

When I compile I get the error: "incompatible types when assigning to type 'double *' from type 'double'" on lines 81, 85, 90, 91.

The project is to take a unit conversion tool and incorporate multiple functions instead of everything under the main().

http://pastebay.net/1181184


回答1:


Try dereferencing the pointer:

*pKelvin = PROD((fahrenheit+459.67),ytemp);
^



回答2:


All of the errors you're getting are variations on a theme. Take this line, for example:

pKelvin = PROD((fahrenheit+459.67),ytemp);

Here, pKelvin has type double*, meaning that it's a pointer to an object of type double. On the other hand, the right-hand side has type double, meaning that it's an actual double. C is complaining because you can't assign doubles to double*s, since they represent fundamentally different types.

To fix this, you probably want to write

*pKelvin = PROD((fahrenheit+459.67),ytemp);

This says "store the value of PROD((fahrenheit+459.67),ytemp) at the double pointed at by pKelvin. This works because you're now assigning a double to an object of type double.

More generally, if you ever see an error like this one, it probably means you're assigning a pointer to a non-pointer or vice-versa.

Hope this helps!



来源:https://stackoverflow.com/questions/14765788/incompatible-types-when-assigning-to-type-c

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