Class Unable to determine overload to use

Monkey Forums/Monkey Programming/Class Unable to determine overload to use

malublu(Posted 2016) [#1]
Why i get this error?
Unable to determine overload to use Method or Function
On line Test.Test(str)
Class Test
	Field lala:String
	Method New(str:String)
		lala = str
	End
	Method Test:Test(str:String)
		Multiply(Test.Test(str))
		Return Self
	End
	Function Test:Test(str:String)
		Return New Test(str)
	End
End



Goodlookinguy(Posted 2016) [#2]
Because you can't do that.

"Test.Test(str)" will be interpreted as being "Test(str)" since you're already in the scope of class "Test". Since it is interpreted as "Test(str)", then the overload resolver will have trouble determining whether or not the function or method should be used.


ImmutableOctet(SKNG)(Posted 2016) [#3]
The issue here is that you have both a function and a method sharing the same arguments and name. This is ambiguous, not to mention horribly confusing. The best choice here is to use a different function or method name. Better yet, make neither the same as the class, because that does nothing but add even more confusion.

Sure, the compiler's smart enough to figure out that the class and method or function is different, but that doesn't mean you aren't still making your code hard to read and maintain.

Is that just how you threw together the example, or is your normal code like that? If so, it just sounds unnecessary to me; you already have a perfectly good constructor, thus making the 'Test.Test' function completely useless. The method on the other hand does something different, although in this context it's still confusing, especially to those with a C-like language background.

Just to show how confusing this setup can get, here's what I did to test the example you posted:


Notice how I had to add an integer argument to fix overload resolution.

At any rate; don't mix function and method signatures lightly. It's certainly something you can do, but that doesn't mean you should normally do it.


malublu(Posted 2016) [#4]
It's was only a test.
I programming 3 Years, but me is never something noticed.
I know that is a bad idea.
Thank you Goodlookinguy for the short answer.
This was the Answer that i would have.
I thought the functions and methods have different signatures.
So i was Surprised that this not working.

Also thank you to ImmutableOctet(SKNG) for the big answer.
That answer should programmers help, for programming design.

None of my classes is called by the name Test.
Also no class have the same method name as the class name.