1

ベクトルにゲッターとセッターを使用する方法はありますか?

たとえば、私のメインクラスで、書きたいと思います

myVector.push(item);

別のクラスでは、次のように書いています。

public function get myVector():Vector.<int> {
     return _opponentCardList;
}

public function set myVector(myVector:Vector.<int>):void {
     _myVector = myVector;
}

_myVector を Vector に設定する必要があるため、これは実際には機能しません。しかし、push()、pop()、または splice だけが必要な場合はどうでしょうか?

4

1 に答える 1

1

あなたのゲッターとセッターは異なる変数を使用しています - それは意図的なものですか?

ゲッター/セッターが別のクラスにある場合、そこからアクセスする前にmyVector、そのクラスのインスタンスがクラスに必要です。Main

//in the Main class.
var obj:OtherClass = new OtherClass();
//the constructor of OtherClass should initialize _myVector
//otherwise you will get a null pointer error (1009) in the following line
obj.myVector.push(item);
于 2010-01-08T04:50:10.173 に答える