【发布时间】:2013-08-05 20:52:39
【问题描述】:
我有一个分层的 ADT,我试图从客户端调用一个较低的成员。具体来说,我有一个 Graph ADT,它依赖于 List ADT 来存储邻接关系。我在调用客户端中的 List ADT 等方法时遇到问题。
我将 List.h 包含在 Graph.h 中,然后将 Graph.h 包含在客户端中。 (但向客户端添加包含 List.h 不会改变任何内容)。编译器调用Graph.h中的List构造函数没有问题,但是当我调用list方法比如length时却告诉我“调用的对象长度不是函数”。
GraphClient.c 摘录
#include <stdio.h>
#include <stdlib.h>
#include "Graph.h"
int main(int argc, char** argv) {
List L = newList();
printf("%d",length(L));
}
List.c 摘录
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "List.h"
List newList(void) {
List L = malloc(sizeof (ListObj));
L->front = L->back = L->current = NULL;
L->cursor = -1;
L->length = 0;
return (L);
}
int length(List L) {
if (L == NULL) {
printf("List error: calling length on NULL List reference");
exit(1);
}
return (L->length);
}
Graph.c 摘录
#include <stdlib.h>
#include "Graph.h"
#include "List.h"
我是否正确分层包含?如果我不尝试在客户端内部调用 List 方法,程序可以正常工作,但如果不这样做,我将无法满足规范。
【问题讨论】:
-
你的
#include "List.h"不是int main(...){...}吗? -
我们应该猜测
List.h的内容吗?以及您不发布minimal complete example 的原因?
标签: c