error C2371: 'functionname' redefinition: different basic types
Asked Answered
B

1

13

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

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().

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;
}*/
Bequest answered 9/11, 2013 at 20:39 Comment(1)
C
24

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

Solve this by adding a declaration before main():

double getgrundflaeche(double r);

int main(void){
Creswell answered 9/11, 2013 at 20:46 Comment(2)
Thank you! I thought that this isn't needed in C and in the code examples i got, there was never a function declared. But the main function was the last function in the code file in the examples.Bequest
That would also solve the problem - the function's declaration needs to be seen one way or another.Creswell

© 2022 - 2024 — McMap. All rights reserved.