如何在OCAML类中声明记录

时间:2009-03-08 01:03:23

标签: class object class-design ocaml

我想在类中声明一条记录,如下所示:

class player (x, y)=
     object(self)
     type gun = {x:int; y:int; active:bool}
     val guns = Array.create 5 {x=0; y=0; active=false}
....

但编译器声称此行是语法错误:type gun = {x:in ....

在类之外宣布

type :  gun = {x:int; y:int; active:bool}
class player (x, y)=
     object(self)
     val guns = Array.create 5 {x=0; y=0; active=false}
....

错误是:未绑定的枪值。

所以任何人都知道如何以其他方式达到相同的功能? 谢谢!

*********解决了***

Bizare现在正在外面宣布类型时工作,谢谢

1 个答案:

答案 0 :(得分:2)

为什么不在类定义之外定义类型枪?