Maps. expecting class member declaration.
Monkey Forums/Monkey Programming/Maps. expecting class member declaration.
| ||
| While following along in Jim's most excellent video tutorials: http://www.youtube.com/watch?v=VHr90rUZvwg I get this error when trying to compile. Syntax error - expecting class member declaration. Since the video is a year old or more, I guess something has changed in Monkey where what he shows is no longer valid.
Class PersonMap<T> Extends Map<Int, T>
Method Compare(key1:Int, key2:Int)
Return key1 - key2
Return
End
Function Main:Int()
Local people:PersonMap<String>= New PersonMap<String>()
people.Add(24601,"Fred")
people.Add(12345,"Sally")
people.Set(43124,"Gary")
people.Set(12345,"Sallyann")
people.Get(12345)
For Local key:Int = Eachin people.Keys()
Print("ID: "+keys+" Name: "+people.Get(key))
End
Return 0
End
That being so, how would you "fix" the code above ? |
| ||
| I think I see part of the problem but do correct me if I am wrong.. the keyword "Map" in no longer valid in Monkey. |
| ||
| First a Method should End with End or End Method not a 'Return' and there is a syntax error within the print statement +keys+ should read +key+ And if you ran the code once fixed in Strict mode then it wouldn't work unless you defined the return type in Compare e.g Compare:Int Edit: You should aways use strict mode as this can trap any coding errors. |
| ||
| You are so right dawlane. What a stupid loofa I must look like. LOL! I have been staring at code too long today.
Class PersonMap<T> Extends Map<Int, T>
Method Compare(key1:Int, key2:Int)
Return key1 - key2
End
End
Function Main:Int()
Local people:PersonMap<String>= New PersonMap<String>()
people.Add(24601,"Fred")
people.Add(12345,"Sally")
people.Set(43124,"Gary")
people.Set(12345,"Sallyann")
people.Get(12345)
For Local key:Int = Eachin people.Keys()
Print("ID: "+key+" Name: "+people.Get(key))
End
Return 0
End
|