c++ - 获取错误 : "error: conflicting types for ‘call_celsius’ "and "note: previous implicit declaration of ‘call_celsius’ was here"

标签 c++ c opengl

我无法让这段代码在 gcc 中编译。我试过更改 call_celsius 来计算以及将其从大写更改为小写。我不确定是不是因为我没有声明一个我认为不是这种情况的变量,或者我是否错误地调用了函数。

/* Homework 1 Question 2 */

/* Purpose: Takes a depth (in kilometers) inside the earth */
/* as input data; Computes and displays the temperature at */
/* depth in degrees Celsius and degrees Fahrenheit.        */

#include <stdio.h>

int main(void)
{

/* Declare Variables */

double depth;
double Celsius;
double Fahrenheit;

/* Obtain Data */

printf("Please enter depth(in kilometers) inside the Earth:  ");
scanf("%lf",&depth);

/* Calculate */

Celsius = call_celsius(depth);
Fahrenheit = call_fahrenheit(Fahrenheit);

/* Output */

printf("The temperature at %lf kilometers is %lf degrees Celsius and %lf degrees       Fahrenheit",depth, Celsius, Fahrenheit);

return 0;
}

double call_celsius(double depth)
{
return((10 * depth) + 20);
}

double call_fahrenheit(double Celsius)

{
return((1.8 * Celsius) + 32);
}

这些是我收到的错误

homework1question2.c:35:8: error: conflicting types for ‘call_celsius’
double call_celsius(double depth)
    ^
homework1question2.c:25:11: note: previous implicit declaration of ‘call_celsius’ was here
Celsius = call_celsius(depth);
       ^
homework1question2.c:40:8: error: conflicting types for ‘call_fahrenheit’
double call_fahrenheit(double Celsius)
    ^
homework1question2.c:26:14: note: previous implicit declaration of ‘call_fahrenheit’ was    here
Fahrenheit = call_fahrenheit(Fahrenheit);

最佳答案

在使用它们之前,您没有声明 call_celsiuscall_fahrenheit。添加函数原型(prototype)或声明和定义函数。以下是前向声明的示例:

double call_celsius(double depth);
double call_fahrenheit(double Celsius);
int main(void) {

关于c++ - 获取错误 : "error: conflicting types for ‘call_celsius’ "and "note: previous implicit declaration of ‘call_celsius’ was here",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641244/

相关文章:

c++ - 将结构作为 char 缓冲区传递给 proc 条目

C QueueLinkedList 字符串变量不起作用

c++ - Freetype正确尺寸渲染

c++ -/proc/fd 文件描述符显示什么?

c++ - 将 lambda 推导为 std::function<T>

c++ - 在 operator[] 中混合引用和值行为

c - LoadImage 的工作方式因获胜颜色设置而异

c - 如何在 shell 命令行中输入退格字符?

c++ - 在 OpenGL 中围绕对象而不是相机周围的对象旋转 'camera'

c++ - 如何替换以下(已弃用)OpenGL 函数?