我正在尝试编写一个书店程序,并且在我的函数实现中的源代码文件中出现“多重定义”的错误。
这是我的 Book.c 文件:
#include "Book.h"
void scanBook(book_t* bk) //error here
{
//implementation here
}
这是我的 Book.h 文件:
#pragma once
#include <stdio.h>
typedef char* str;
typedef enum Genre {Education, Business, Novel} genre_t;
typedef struct Book{
str ISBN;
str title;
str author;
float price;
int quantity;
genre_t genre;
} book_t;
void scanBook(book_t* bk);
这是我的 main.c 文件:
#include "Book.h"
#include "Book.c"
int main()
{
return 0;
}
错误发生在 Book.c 中的 scanBook 函数中,但我不知道为什么,因为我包含了头文件以及 #pragma 一次,并且在头文件中我声明了该函数。它说 'scanBook' 和 obj\Debug\Book.o .... 的多个定义首先在这里定义。
任何帮助或澄清将不胜感激!