C语言 错误 C2371:'functionname' 重新定义:不同的基本类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19882804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:55:54  来源:igfitidea点击:

error C2371: 'functionname' redefinition: different basic types

cfunction-prototypesredefinition

提问by user2974830

i have a Problem. I use Visual Studio 2013 and get the following Error:

我有个问题。我使用 Visual Studio 2013 并收到以下错误:

Error C2371: 'getgrundflaeche' redefinition: different basic types.

I don't know why i get this Error. I get the same Error with VS12, when i try to call the function getgrundflaeche().

我不知道为什么会出现此错误。当我尝试调用函数时,VS12 出现相同的错误getgrundflaeche()

Here is the Code:

这是代码:

#include <stdio.h>
#define PI 3.14159265359

int main(void){
    double h = 0, d = 0, r = 0, G = 0, V = 0, M = 0, O = 0;

    printf("Geometrie Zylinder:\nBitte geben sie den Durchmesser d ein (cm): ");
    scanf_s("%lf", &d);
    printf("Bitte geben sie die H?he h ein (cm): ");
    scanf_s("%lf", &h);
    r = d / 2;

    G = getgrundflaeche(r);
    /*V = get_volumen(r, h);
    M = get_mantelflaeche(d, h);
    O = get_oberflaeche(M, G); */

    system("CLS");

    printf("Eingaben:\nDurchmesser d: %lf cm\nH?he h: %lf cm", d, h);
    system("PAUSE");

    return 0;
}

double getgrundflaeche(double r){
    return (r*r);
}
/*
double get_volumen(double r, double h){
return r*r*h*PI;
}

double get_mantelflaeche(double d, double h){
return d*h*PI;
}

double get_oberflaeche(double M, double G){
return M+2*G;
}*/

回答by Paul Roub

You never declared getgrundflaechebefore calling it. The compiler assumes undeclared functions return int. The later function definition is, of course, different.

getgrundflaeche在调用它之前从未声明过。编译器假定未声明的函数返回int。后面的函数定义当然是不同的。

Solve this by adding a declaration before main():

通过在之前添加声明来解决这个问题main()

double getgrundflaeche(double r);

int main(void){