本文介绍了错误C2371:重定义;不同的基本类型 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

#include <stdio.h>
#include <stdlib.h>

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

  for (i = (array_size - 1); i > 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (numbers[j-1] > numbers[j])
      {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}

// exer1 - A

void sort(int** arr, int arrsize) {
    int i = 0;
    // sort....
    for(; i < arrsize; ++i) {
        sortint((*(arr+i))+1,  **(arr+i));
    }
}

// Exer1 - B

void print(int** arr, int arrsize) {
    int i = 0, j, size, *xArr;
    for(; i < arrsize; ++i) {
        size = **(arr+i);
        xArr = *(arr+i);
        printf("size: %d: ", size);
        // print elements
        for(j = 1; j <= size; ++j) printf("[%d], ", *(xArr+j));
        printf("\n");
    }
}

// Exer2:

void exera() {
    int* ptr = (int*)malloc(sizeof(int));
    if(!ptr) exit(-1);
    eb(ptr);
    free(ptr);
}

void eb(int* ptr) {
    int* arr = (int*) malloc(sizeof(int) * (*ptr));
    int i = 0;
    for(; i < *ptr; ++i) scanf("%d", arr+i);
    ec(arr, *ptr);
}

void ec(int* arr, int size) {
    int i;
    sortint(arr, size);
    for(i = 0; i < size; ++i) printf("[%d], ", *(arr+i));
}

int main() {
    // Exer1:
    int a[] = {4,3,9,6,7};
    int b[] = {3,2,5,5};
    int c[] = {1,0};
    int d[] = {2,1,6};
    int e[] = {5,4,5,6,2,1};
    int* list[5] = {a,b,c,d,e};
    sort(list, 5); // A
    print(list, 5); // B
    printf("\n\n\n\n\n");
    // Exer2:
    exera();
    fflush(stdin);
    getchar();
    return 0;
}

我得到这些错误:

I get these errors:

Error   2   error C2371: 'eb' : redefinition; different basic types
source.c    56

Error   4   error C2371: 'ec' : redefinition; different basic types 
source.c    63

Warning 1   warning C4013: 'eb' undefined; assuming extern returning int    
source.c    52

Warning 3   warning C4013: 'ec' undefined; assuming extern returning int    
source.c    60

我试图改变函数名 - 白白

I tried to change function names - for nothing.

为什么被证明错误?我使用Visual C ++防爆preSS 2010。

Why is that error is being shown? I'm using Visual C++ Express 2010.

推荐答案

您正在试图调用 EB EC 之前,他们被声明或定义。移动的定义 EC EB 和前后 EXERA 。你也可以期待您定义其中的任何像这样前声明你的功能:

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) ;

这篇关于错误C2371:重定义;不同的基本类型 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:41