我检查并没有找到任何可以帮助我的材料,所以我不得不问。这是代码:
列表.h:
typedef struct List_t *List;
列表.c:
#include "list.h"
#include <stdlib.h>
#include <stdio.h>
typedef struct Item_t
{
struct Item_t* next;
ListElement data;
}*Item;
typedef struct List_t
{
Item head;
Item iterator;
CopyListElement copyFunc;
FreeListElement freeFunc;
};
list_example_test.c:
#include "list.h"
#include <stdlib.h>
#include <stdio.h>
ListElement copyA(ListElement a)
{
return a;
}
void destroyA(ListElement a)
{
}
bool testListCreate();
bool testListCopy()
{
List list1=listCreate(copyA,destroyA);
listInsertFirst(list1,(void*)6);
listInsertFirst(list1,(void*)2);
listInsertFirst(list1,(void*)1);
List list2=listCopy(list1);
listClear(list1);
if(list2->head==NULL) //here is the error!!
{
return false;
}
return true;
}
最后一段代码应该检查 listCopy() 函数是否有效。编译器识别名称 List,当我输入“list2->”时,它甚至建议使用 List 的字段自动完成(在这种情况下,我选择了“list2->head”。是什么导致了问题以及如何解决它?谢谢!