问题
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