简体   繁体   English

错误:*(int **,int,int,int)'的间接级别与'int()'不同,如何解决我的情况?

[英]Error: *(int **,int,int,int)' differs in levels of indirection from 'int ()', How can I fix it in my case?

I am trying to solve one of my homework problems that I was given. 我正在尝试解决我遇到的一项家庭作业问题。 I am supposed to create a linked list and an array. 我应该创建一个链表和一个数组。 The elements of the linked list is a struct of three ints and a pointer to the next node. 链表的元素是三个整数的结构以及指向下一个节点的指针。 The elements of the array are structs of three ints as well. 数组的元素也是三个整数的结构。 A condition to put these specific struct into the linked list& array is when a given matrix fulfills: i+j equals to the element in the matrix in a specific iteration (where i and j are the iteration elements). 将这些特定结构放入链接列表&数组的条件是,当给定矩阵满足时:i + j等于特定迭代中矩阵中的元素(其中i和j是迭代元素)。

 Severity Code Description Project File Line Suppression State Error C2040 'createThreeArr': 'threesome *(int **,int,int,int)' differs in levels of indirection from 'int ()' 

I got this error shown in the title of this post, can anyone help me understand why is this happening? 我在这篇文章的标题中看到了此错误,有人可以帮助我理解为什么会这样吗? What have I done wrong? 我做错了什么?

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

typedef struct threesome
{
    int sum;
    int i;
    int j;
}threesome;

typedef struct list
{
    threesome data;
    struct list* next;
}list;


int createArrayAndList(int** arr, int rows, int cols, threesome** resArr, list** resList)
{
    int num;
    *resList = createThreeList(arr, rows, cols, &num);
    *resArr = createThreeArr(arr, rows, cols, num);
    return num;
}
threesome* createThreeArr(int** arr, int rows, int cols, int num) {
    threesome* new_array;
    int i, j, k;
    if (!num) return NULL;
    new_array = (threesome*)malloc(sizeof(threesome)*num);
    k = 0;
    for (i = 0; i < rows; i++)
        for (j = 0; j < cols; j++)
            if (arr[i][j] == i + j) {
                new_array[k].sum = arr[i][j];
                new_array[k].i = i;
                new_array[k].j = j;
                k++;
            }
    return new_array;
}
list* createThreeList(int** arr, int rows, int cols, int* length_list) {
    int i, j, count = 0;
    list *head = NULL, *temp1 = NULL, *temp2 = NULL;
    for (i = 0; i < rows; i++)
        for (j = 0; j < cols; j++) {
            if (arr[i][j] == (i + j)) {
                temp2 = (list*)malloc(sizeof(list));
                temp2->data = createThree(i + j, i, j);
                temp2->next = NULL;
                if (!count) {
                    head = temp2;
                    temp1 = head;
                    count++;
                    continue;
                }
                else {
                    temp1->next = temp2;
                    temp1 = temp1->next;
                    count++;
                    continue;
                }
            }
        }
    *length_list = count;
    return head;
}
threesome createThree(int num, int i, int j) {
    threesome strc;
    strc.sum = num;
    strc.i = i;
    strc.j = j;
    return strc;
}

You have: 你有:

int createArrayAndList(int** arr, int rows, int cols, threesome** resArr, list** resList)
{
    int num;
    *resList = createThreeList(arr, rows, cols, &num);
    *resArr = createThreeArr(arr, rows, cols, num);
    return num;
}
threesome* createThreeArr(int** arr, int rows, int cols, int num) {
    …

The call to createThreeArr() in createArrayAndList() implicitly declared createThreeArr() (and the call to createThreeList() does roughly the same): 要将呼叫createThreeArr()createArrayAndList()隐式声明createThreeArr()和调用createThreeList()做大致相同):

extern int createThreeList();
extern int createThreeArr();

Those are functions returning an int with undefined (but not variadic) argument lists. 这些是返回带有未定义(但不是可变参数)参数列表的int函数。

When the compiler comes across threesome* createThreeArr(int** arr, int rows, int cols, int num) { it thinks That's not what you said before! 当编译器遇到threesome* createThreeArr(int** arr, int rows, int cols, int num) {它以为那不是您之前所说的! and generates the error message. 并生成错误消息。

Declare or define your functions before calling them. 在调用它们之前声明或定义您的函数。 C99 requires it. C99需要它。 You get better error checking if you do that. 如果这样做,您会得到更好的错误检查。 You can define a static function before it is used without pre-declaring it. 您可以在使用static函数之前先定义它,而无需预先声明它。

static threesome *createThreeArr(int **arr, int rows, int cols, int num);
static list *createThreeList(int **arr, int rows, int cols, int *length_list);
static threesome createThree(int num, int i, int j);
static int createArrayAndList(int** arr, int rows, int cols, threesome** resArr, list** resList);

static int createArrayAndList(int **arr, int rows, int cols, threesome **resArr, list **resList)
{
    …
}

…

If it was my code, all the functions except main() would be static (as above); 如果是我的代码,除main()之外的所有功能都是static (如上所述); if they were visible outside this source file, they'd be declared in a header and the header would be included here and wherever else the functions are used. 如果它们在此源文件之外可见,则将在标头中声明它们,标头将包含在此处以及使用函数的其他位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与&#39;int()&#39;(C)的间接等级不同 - differs in levels of indirection from 'int ()' (C) rename() function 与 int 的间接级别不同 - rename() function differs in levels of indirection from int 警告 C4047:“=”:“int”与“int *”的间接级别不同 - Warning C4047 : '=': 'int' differs in levels of indirection from 'int *' 错误C2040:'void *()'的间接级别与'int()'不同 - Error C2040: 'void *()' differs in levels of indirection from 'int ()' 间接级别与int&#39;int()&#39;不同 - differs in level of indirection from int 'int ()' int与char [2]错误的间接级别不同 - int differs in level of indirection from char[2] error 整数* = 整数? 不同级别的间接 - int* = int ? Different levels of indirection 警告C4047:&#39;=&#39;:&#39;int&#39;的间接级别与&#39;char *&#39;不同 - warning C4047: '=' : 'int' differs in levels of indirection from 'char *' 2 个警告:&#39;int *&#39; 与 &#39;int **&#39; 的间接级别不同,形式参数和实际参数的类型不同 3 - 2 warnings: 'int *' differs in levels of indirection from 'int **' and different types for formal and actual parameter 3 编译器返回错误“ char *(int)”的间接寻址级别与“ int()”不同,即使返回的数据似乎与函数返回类型匹配 - Compiler returns error “char *(int)' differs in levels of indirection from 'int ()'” even though data returned seems to match function return type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM