monkey can't determine what method to use

Monkey Forums/Monkey Programming/monkey can't determine what method to use

c.k.(Posted 2012) [#1]
This error:

Unable to determine overload to use: Method Maze.new(Local nMaze:String,Local delim:String) or Method Maze.new(Local mw:Int,Local mh:Int,Local sp:Int[],Local ep:Int[])


from this code:

[monkeycode]
Local m1:Maze = New Maze(6, 5)
[/monkeycode]

New() method signatures are:

[monkeycode]
Method New(nMaze:String, delim:String = "~n") ' maze in string with a row delimiter (defaults to newline)
Method New(mSeed:Int = Seed)
Method New(mw:Int, mh:Int, sp:Int[] =[1, 1], ep:Int[] =[0, 0])
[/monkeycode]

There shouldn't be any confusion, should there be?


marksibly(Posted 2012) [#2]
Hi,

When searching for matching function signatures, Monkey currently treats any match that needs to make use of default param values as 'inexact'.

This doesn't look right to me though - the above call should really match with the last ctor.

It's actually a simple change to the translator code to fix this, I'm just worried there's a reason I did it in the first place that I've forgotten about!

Will do some more testing, but in the meantime splitting the last ctor into 2 should fix it.


c.k.(Posted 2012) [#3]
Perhaps now you've learned to always comment your code... heheh

By splitting, you mean have this:

[monkeycode]
Method New(mw:Int, mh:Int)
Method New(mw:Int, mh:Int, sp:Int[] =[1, 1], ep:Int[] =[0, 0])
[/monkeycode]

If so, can I call the second New() from the first New(), so I don't have to duplicate the code?


NoOdle(Posted 2012) [#4]
no but you can call a construct method that shares the same code in new.