普通网友 2016-04-01 12:26 采纳率: 100%
浏览 2080

c语言,没定义同名函数,包含头文件时却说重定义了,请大神看看

头文件EnforceJoseph.h

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

struct Node
{
    int password;
    int peopleOfNumber;
    Node *next;
};

Node *first;
Node *last;


//用于遍历约瑟夫环的函数,传入的形参第一个为首地址,第二个是初始上限值
bool Enforce(Node *node, int m)
{
    Node *p = node;
    Node *q = p;
    if ((*p).next == p) return true;
    int i = 0;
    for (; i < m; i++)
    {
        p = (*p).next;
        if (i == 0) continue;
        q = (*q).next;
    }
    m = (*p).password;
    printf("出列的人为:%d", (*p).peopleOfNumber);
    (*q).next = (*p).next;
    free(p);
    Enforce((*q).next, m);
    return true;
}

//建立一个只有一个结点的链表
void setup()
{
    first =(Node *) malloc(sizeof(Node));
    last = first;
    (*last).next = first;
}

//向链表添加数据
void add(int password, int numberOfPeople)
{
    Node *p;
    if (last == first)
    {
        p = first;
    }
    else  p = (Node *)malloc(sizeof(Node));
    (*p).password = password;
    (*p).peopleOfNumber= numberOfPeople;
    (*p).next = first;
    last = p;
}

bool checkIfNull()
{
    Node *q = (*first).next;
    if (((*first).next == first) || (*q).next == first)
        return false;
    else return true;
}

void begin(int m)
{
    Enforce(first, m);
}

下面是包含该头文件的,main函数所在的文件"源.cpp":

 #include<stdio.h>
#include<string.h>
#include "EnforceJoseph.h"


int m;
int pass;
int num;
char yOrN[3];
int main()
{
    void start();
    start();
    system("PAUSE");
}


void start()
{
    void input(int type);
    void check(int type);
    setup();
    input(1);
    input(2);
    input(3);
    check(4);
    begin(m);
}

void input(int type)
{
    void check(int type);
    switch (type)
    {
    case 1:
        printf("请输入m的值\n");
        scanf_s("%d", &m);
        check(1);

        break;
    case 2:
        printf("请输入密码和位置");
        scanf_s("%d %d", &pass, &num);
        check(2);
        add(pass,num);
        break;
    case 3:
        printf("你是否要继续输入?请输入yes或no\n");
        scanf_s("%s", yOrN);
        check(3);
    }
}



void check(int type)
{
    switch (type)
    {
    case 1:
        if (m != (int)m)
        {
            printf("你输入的m值不合要求,请重新输入\n");
            input(1);

        }

    case 2:
        if (pass > m)
        {
            printf("你输入的密码不合要求,重新输入\n");
            input(2);

        }

    case 3:
        if ((strcmp(yOrN, "yes") != 0) && (strcmp(yOrN, "no") != 0))
        {
            printf("请输入yes或no\n");
            input(3);

        }
        else input(2);

        break;
    case 4:
        if (!checkIfNull())
        {
            printf("你建立的链表不合法,请重新建立");
            input(2);

        }

        break;
    }
}

该项目只写了这2个文件。下面上张报错的图:
图片说明

求解决方法

  • 写回答

4条回答 默认 最新

  • 小灸舞 2016-04-01 13:35
    关注

    楼主这是VS2012?我这里可以的

    图片说明

    建议楼主重新生成一下,或者重新创建个工程试试

    评论

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题