3
我在AS3中做了一個表示複數的類。它不會繼承任何東西。我怎樣才能從例如數字?即我想這一點:如何在Actionscript 3中爲自己的類實現強制轉換?
5 as Complex
是一樣的:
new Complex(5);
是有一個神奇的CAST()函數,我可以把我的班?
我在AS3中做了一個表示複數的類。它不會繼承任何東西。我怎樣才能從例如數字?即我想這一點:如何在Actionscript 3中爲自己的類實現強制轉換?
5 as Complex
是一樣的:
new Complex(5);
是有一個神奇的CAST()函數,我可以把我的班?
不怕。 Number
是與您的Complex
類無關的類型。所有您將收到一個:
1067: Implicit coercion of a value of type Number to an unrelated type Complex
我能想到的唯一的事情會做這樣的事情:
asComplex(5);
public function asComplex(num:Number):Complex
{
return new Complex(num);
}
,但不知道有很多點在。