![]() |
#2
yuccn2011-03-22 20:19
|

#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FLASE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int Status;
typedef struct {
int *elem;
int length;
int listsize;
}SqList;
extern Status InitList_Sq(SqList);
extern Status ClearList_Sq(SqList);
extern Status ListLength_Sq(SqList);
extern Status ListInsert_Sq(SqList,int,int&);
extern Status ListDelect_Sq(SqList,int);
extern Status ShowList_Sq(SqList);
#include<stdlib.h>
#define TRUE 1
#define FLASE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int Status;
typedef struct {
int *elem;
int length;
int listsize;
}SqList;
extern Status InitList_Sq(SqList);
extern Status ClearList_Sq(SqList);
extern Status ListLength_Sq(SqList);
extern Status ListInsert_Sq(SqList,int,int&);
extern Status ListDelect_Sq(SqList,int);
extern Status ShowList_Sq(SqList);
这儿是头文件定义,取第一个InitList_Sq()介绍下问题:

#include"DCT.h"
void main(){
int a,i,e;
int b[5]={54,79,32,74,91};
SqList L;
//此处省略N行
scanf_s("%d",&a);
switch(a){
case 1:InitList_Sq(L);
for(int m=1;m<=5;m++)ListInsert_Sq(L,m,b[m-1]);
void main(){
int a,i,e;
int b[5]={54,79,32,74,91};
SqList L;
//此处省略N行
scanf_s("%d",&a);
switch(a){
case 1:InitList_Sq(L);
for(int m=1;m<=5;m++)ListInsert_Sq(L,m,b[m-1]);
这儿是引用,至于定义是放在另一个.CPP文件里的,如下:

#include"DCT.h"
Status InitList_Sq(SqList &L){
L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
//此处省略N行
}
Status InitList_Sq(SqList &L){
L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
//此处省略N行
}
但是编译的时候就会提示在mian.obj里有相关于InitList()的无法解析的函数,如下:
1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl ListDelect_Sq(struct SqList,int)" (?ListDelect_Sq@@YAHUSqList@@H@Z) referenced in function _main
网上查了说一般有两种情况,一种是调用库了却没声明,看了看好像没有调用啊,第二组是说函数声明了却没定义,我就在想是不是要在Main.cpp中也要定义,但这样分出来的专门写功能函数的.cpp不就没有意义了说,很困惑啊,查了C的书,上面的示例貌似可以完美分开,于是就更纠结了,额,在学数据结构,应为里面不是是用C++来写的,所以果断从C升级到C++,难道里面有没考虑到的?求教啊求教,就这最后一个问题了,卡的我快疯了……