晕了,编译老出错,各位大侠帮我看看

我是用vc++编的c程序 分了3格文件
一,sqlist.h
#define ture 1
#define palse 0
#define ok 1
#define error 0
#define overflow -2
#define ml 10
typedef struct sqlist
{
int list[ml];
int size;
int maxsize;
}sqlist;
2,sqlisths.cpp
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include"sqlist.h"
//顺序表的初始化
sqlist *init_list(sqlist *L,int ms)
{
L=(sqlist*)malloc(ms*sizeof(sqlist));
if(!L)
{
printf("Memory allocation failurel\n");
exit(overflow);
}
else
L->size=0;
L->maxsize=ml;
return L;
}
3 sqlistmain.cpp
#include"sqlisths.cpp"
#include<iostream>
void main()
{
sqlist a,*b;
b=init_list(&a,ml);
printf("list=%p\tsize=%d\tmaxsize=%d\t", b->list,b->size,b->maxsize);
}
老是错,搞了几小时了还没搞好,只好请大家来帮我看看,分不是问题啊
错误提示
--------------------Configuration: sqlist - Win32 Debug--------------------
Linking...
sqlistmain.obj : error LNK2005: "struct sqlist * __cdecl init_list(struct sqlist *,int)" (?init_list@@YAPAUsqlist@@PAU1@H@Z) already defined in sqlisths.obj
Debug/sqlist.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.

sqlist.exe - 1 error(s), 0 warning(s)

你自己看下错误提示:
sqlistmain中的init_list 函数 已经在sqlisths.obj 中定义了

在main 里,你 怎么 include cpp 文件呢?
你可以 将 init_list 函数定义和实现 直接在 sqlistmain.cpp 中。
也就是说,合并sqlisths.cpp 和 sqlistmain.cpp 2个文件的内容。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-10
默认路径没有设置吧,好像是,该完试试
第2个回答  2010-05-10
所有的.cpp和.h文件都加到工程里,然后
sqlist.h
的最后加上
sqlist *init_list(sqlist *L,int ms);

sqlistmain.cpp

#include"sqlisths.cpp"
改为
#include"sqlisths.h"
第3个回答  2010-05-10

我用你的源代码试了,没有任何问题,可能是你用的VC环境的事,有的VC经常出现莫名奇妙的错误问题,但是换台机器就没有事了。

相似回答