Smalltalk で Array のサブクラスとして非常に単純な Vector クラスを作成しようとしています。クラスを作成するための私のコードは次のようになります。
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'>
]
]
明らかに、私はまだメソッドを書いていませんが、最初にこの部分を機能させようとしています。上記のようにクラスを作成した後、 v := Vector new: 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
これは Array のサブクラスであるため、この方法で Vector を作成できると想定していました。これを行う最善の方法は何ですか?ありがとう!
編集 - 私はそれを理解しました。チュートリアルを深く読んだ後、 <shape: #pointer> を含める必要があることがわかりました