1
我想创建一个非常简单的Vector类作为Smalltalk中Array的子类。我创建类的代码如下所示:Basic Smalltalk子类
Array subclass: #Vector
Vector comment: 'I represent a Vector of integers'
Vector class extend [
new [
| r |
<category: 'instance creation'>
r := super new.
r init.
^r
]
]
Vector extend [
init [
<category: 'initialization'>
]
]
显然我还没有写任何方法,但我只是试图让这部分工作第一。创建后的类如上,如果我输入: 五:=矢量新:4 我得到错误:
Object: Vector error: should not be implemented in this class, use #new instead
SystemExceptions.WrongMessageSent(Exception)>>signal (ExcHandling.st:254)
SystemExceptions.WrongMessageSent class>>signalOn:useInstead: (SysExcept.st:1219)
Vector class(Behavior)>>new: (Builtins.st:70)
UndefinedObject>>executeStatements (a String:1)
nil
我曾以为,既然是数组的一个子类,我可以创造一个矢量这种方式。做这件事的最好方法是什么?谢谢!
编辑 - 我想通了。在深入阅读教程之后,我发现我需要包含<形状:#指针>
我觉得你有这个人的同样的问题:http://stackoverflow.com/questions/5613363/gnu-smalltalk-problem-with-example-in-tutorial-object-creation – andrewdotnich 2012-02-27 23:58:00
我看着那个帖子,改变了这些事情,但我仍然得到了同样的结果。 – FlapsFail 2012-02-28 02:36:56