Error C2371: redefinition; different basic types - why?

后端 未结 3 966
一个人的身影
一个人的身影 2021-01-04 03:20

I have the following code:

#include 
#include 

// helping
void sortint(int numbers[], int array_size)
{
  int i, j, temp;

           


        
相关标签:
3条回答
  • 2021-01-04 03:56

    You call eb from exera, before eb is declared. The compiler assumes it'll return int then finds an implementation that returns void further down the file.

    The most common fix is to declare your local functions at near top of your file

    void eb(int* ptr);
    // repeat for each other function which generates the same error
    
    0 讨论(0)
  • 2021-01-04 03:56

    If you are going to place the function eb after the point at which it is called, then you need to place a prototype for it before it is called... otherwise, C will use the default prototype and then your function ends up redefining it, thus the error you received.

    Alternatively, you can move the functions themselves before they are used in the source file, but that's not always possible. Placing prototypes at the top of the file or, better still, in a header file you can include anywhere you will use the functions is the best alternative.

    0 讨论(0)
  • 2021-01-04 04:11

    You are trying to call eb and ec before they are declared or defined. Move the definition of ec before eb and both before exera. You could also forward declare your functions before you define any of them like so:

    void eb(int* ptr) ;
    void ec(int* arr, int size) ;
    
    0 讨论(0)
提交回复
热议问题