Incompatible types when assigning to type - C [clo

2019-08-31 01:05发布

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

2条回答
Juvenile、少年°
2楼-- · 2019-08-31 01:36

Try dereferencing the pointer:

*pKelvin = PROD((fahrenheit+459.67),ytemp);
^
查看更多
Emotional °昔
3楼-- · 2019-08-31 01:40

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!

查看更多
登录 后发表回答