这样的单元之间的引用为什么不行?(100分)

  • 主题发起人 demogorgon
  • 开始时间
D

demogorgon

Unregistered / Unconfirmed
GUEST, unregistred user!
// A引用了B和C
unit A;
interface
uses B,C;
type
TA = class
public
b: TB;
c: TC;
end;
end.

//B B类引用了A和C
unit B;
interface
uses
C;
type
TB = class
public
c: TC;
a: TA;
end;
implementation
USES
A;
end.

//类C引用了A
unit C;
interface
type
TC = class
public
a: TA;
end;
implementation
uses
A;
end.
 
a only use b (no use c)
就是这样,A可能通过B来访问C,不可以像你这样做!!
 
相互之间在interface部分的uses里面不能相互引用的,要通过其他办法引用
 
有什么办法呢?
 
在implementation引用..., 不过你的不可以, 你的需要把他们放到一个单元了
 
递归定义可以用指针来实现,放在同一个单元不是更好一些,何必绕弯子
 
放到一个单元也报错,怎么向前申明呢?//3x
 
unit Unit2;
interface
type
TA = class
public
b: TB;
end;

TB = class
public
a: TA;
end;

implementation
end.
这样也不行啊~大虾快帮忙~
 
unit Unit2;
interface
type
TB = class;
//加一行
TA = class
public
b: TB;
end;

TB = class
public
a: TA;
end;

implementation
end.
 
i love u all~
 
多人接受答案了。
 
顶部