2013-02-28 108 views
0
package 
{ 
    import flash.events.* 
    import flash.ui.* 

    public class tank() //1084: Syntax error: expecting leftbrace before leftparen. 
    { 
     //other stuff 
    } 
} 

這是一個錯誤的重複開溜了,我想不通,它似乎是錯誤1084的一個版本,我不能使用Google發現...錯誤1084:期待leftbrace前左括號

我試圖把左大括號的括號之前該行後整條生產線,其他錯誤之前...

回答

1

你的語法不正確。如果你想創建一個班級,你需要擺脫左括號和右括號(就像錯誤告訴你的那樣,你給了它一個錯誤的輸入,並期待一個左大括號({))。因此,請嘗試以下操作:

package 
{ 
import flash.events.*; // Put a semi-colon after imports 
import flash.ui.*; // Here too 

//public class tank() // 1084: Syntax error: expecting leftbrace before leftparen. 
public class tank // This should not error on you. 
{ 
    //other stuff 
} 
} 

希望有所幫助!

1

類定義不使用括號。 您可能會將類定義與構造函數混淆,該構造函數使用括號並嵌套在類中。

基本上,只要去掉()在這裏就結束了:

public class tank 

然後您的構造函數使用括號像這樣是內:

public class tank 
{ 
    // This is a constructor. It is a public method with the same name as 
    // the class it is defined within, and is called when an instance of 
    // this class is created. 
    public function tank() 
    { 
     // 
    } 
} 
+0

感謝,也感謝@ThePhD謝謝,現在我用@符號永遠不會有同樣的感受......不知道構造函數,除非這是函數的一個奇特名稱,但我必須將它們與函數混合起來。謝謝。 – theHeretic 2013-02-28 05:21:31

+0

@ user1743752構造函數只是一個*函數,其名稱與定義它的類相同*。當你創建一個新的類的實例時,你可以將代碼放在那裏,以便你立即運行。 – Marty 2013-02-28 05:24:59