Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译器抱怨类型冲突_C++_C_Compiler Errors - Fatal编程技术网

C++ 编译器抱怨类型冲突

C++ 编译器抱怨类型冲突,c++,c,compiler-errors,C++,C,Compiler Errors,我正在尝试构建链接列表,但在编译代码时出现以下错误: In file included from linkedlist.c:1: linkedlist.h:9: warning: 'struct list_t' declared inside parameter list linkedlist.h:9: warning: its scope is only this definition or declaration, which is probably not what you want li

我正在尝试构建链接列表,但在编译代码时出现以下错误:

In file included from linkedlist.c:1:
linkedlist.h:9: warning: 'struct list_t' declared inside parameter list
linkedlist.h:9: warning: its scope is only this definition or declaration, which is probably not what you want
linkedlist.h:12: warning: 'struct list_t' declared inside parameter list
linkedlist.c: In function 'main':
linkedlist.c:11: warning: passing argument 2 of 'execute_choice' from incompatible pointer type
linkedlist.c: At top level:
linkedlist.c:28: error: conflicting types for 'execute_choice'
linkedlist.h:9: error: previous declaration of 'execute_choice' was here
linkedlist.c:56: error: conflicting types for 'create_node_in_linked_list'
linkedlist.h:12: error: previous declaration of 'create_node_in_linked_list' was here
linkedlist.h:9: warning: 'struct list_t' declared inside parameter list
linkedlist.h:9: warning: its scope is only this definition or declaration, which is probably not what you want
linkedlist.h:12: warning: 'struct list_t' declared inside parameter list
make: *** [all] Error 1
但是,我同时检查了源文件和头文件,“execute_choice”函数在这两个文件中都有匹配的声明。以下是我的源文件和头文件:

源文件:

#include "linkedlist.h"

int main (void)
{
    int choice;
    list_t* list;
    list = (list_t*)sizeof(list_t);

    while (1) {
        choice = display_menu_choices();
        execute_choice(choice, list);
    }
}

int display_menu_choices(void)
{
    int menu_choice;

    printf ("Please select from the following options\n");
    printf ("0. Exit program\n");
    printf ("1. Generate a linkedlist\n");
    printf ("2. Sort a linkedlist\n");
    scanf ("%d", &menu_choice);

    return menu_choice;
}

void execute_choice(int menu_choice, list_t* list)
{
    switch (menu_choice) {
        case GEN_LL:
        generate_linked_list();
        break;

        case SORT_LL:
        sort_linked_list();
        break;

        case EXIT:
        exit(0);
    }

    return;
}

void generate_linked_list(void)
{
    return;
}

void sort_linked_list(void)
{
    return;
}

void create_node_in_linked_list(list_t* list)
{
    return;
}
#include <stdlib.h>
#include <stdio.h>

#define EXIT 0
#define GEN_LL 1
#define SORT_LL 2

int display_menu_choices(void);
void execute_choice(int, struct list_t*);
void generate_linked_list(void);
void sort_linked_list(void);
void create_node_in_linked_list(struct list_t*);

typedef struct node_t{
    struct node_t* current;
    struct node_t* next;
    int value;
} node_t;

typedef struct list_t{
    struct node_t* start;
} list_t;
标题:

#include "linkedlist.h"

int main (void)
{
    int choice;
    list_t* list;
    list = (list_t*)sizeof(list_t);

    while (1) {
        choice = display_menu_choices();
        execute_choice(choice, list);
    }
}

int display_menu_choices(void)
{
    int menu_choice;

    printf ("Please select from the following options\n");
    printf ("0. Exit program\n");
    printf ("1. Generate a linkedlist\n");
    printf ("2. Sort a linkedlist\n");
    scanf ("%d", &menu_choice);

    return menu_choice;
}

void execute_choice(int menu_choice, list_t* list)
{
    switch (menu_choice) {
        case GEN_LL:
        generate_linked_list();
        break;

        case SORT_LL:
        sort_linked_list();
        break;

        case EXIT:
        exit(0);
    }

    return;
}

void generate_linked_list(void)
{
    return;
}

void sort_linked_list(void)
{
    return;
}

void create_node_in_linked_list(list_t* list)
{
    return;
}
#include <stdlib.h>
#include <stdio.h>

#define EXIT 0
#define GEN_LL 1
#define SORT_LL 2

int display_menu_choices(void);
void execute_choice(int, struct list_t*);
void generate_linked_list(void);
void sort_linked_list(void);
void create_node_in_linked_list(struct list_t*);

typedef struct node_t{
    struct node_t* current;
    struct node_t* next;
    int value;
} node_t;

typedef struct list_t{
    struct node_t* start;
} list_t;
#包括
#包括
#定义出口0
#定义第1代
#定义排序规则2
int显示菜单选项(无效);
void execute_choice(int,struct list_t*);
作废生成链接列表(作废);
无效排序链接列表(void);
在链接列表(结构列表)中创建节点;
类型定义结构节点{
结构节点_t*当前;
结构节点*next;
int值;
}节点t;
类型定义结构列表{
结构节点启动;
}名单;;

此外,一般的提示是欢迎的!请评论我的代码,尽管你觉得有必要-如果没有人指出我的错误,我将永远不会从中吸取教训=)谢谢

您必须先声明类型,然后才能尝试使用它


因此,如果在函数原型之前移动结构定义/typedef,编译器应该停止抱怨隐式/冲突定义。

在尝试使用它之前,必须声明类型


因此,如果在函数原型之前移动struct definitions/typedef,编译器应该停止抱怨隐式/冲突的定义。

头文件中的内容顺序是错误的。
typedef
应出现在函数定义之前。所以行动吧

typedef struct node_t{
  struct node_t* current;
  struct node_t* next;
  int value;
} node_t;

typedef struct list_t{
  struct node_t* start;
} list_t;
以前

int display_menu_choices(void);
void execute_choice(int, struct list_t*);

头文件中的内容顺序错误。
typedef
应出现在函数定义之前。所以行动吧

typedef struct node_t{
  struct node_t* current;
  struct node_t* next;
  int value;
} node_t;

typedef struct list_t{
  struct node_t* start;
} list_t;
以前

int display_menu_choices(void);
void execute_choice(int, struct list_t*);

它看起来像C,而不是C++。您正在使用哪个编译器,在哪个系统上?
typedef
移动到原型之前。搜索第一个警告消息的第一个结果之一。它看起来像C,而不是C++。您正在使用哪个编译器,在哪个系统上?
typedef
移动到原型之前。搜索第一条警告消息的第一个结果之一。感谢您的帮助-编译成功!感谢您的帮助-编译成功!