New topic: Overloading: How do I tell RB which method to use?
<http://forums.realsoftware.com/viewtopic.php?t=29716> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message Ford Prefect Post subject: Overloading: How do I tell RB which method to use?Posted: Mon Aug 24, 2009 1:46 pm Joined: Mon Jul 30, 2007 6:11 am Posts: 60 Location: Germany I've overloaded the Constructor of a class, like this (simplified): Code:Sub Constructor(number As Double) ... End Sub Sub Constructor(number As UInt32) ... End Sub Now when I call it, RB says that "There are several items with this name and it is not clear which one the call refers to". This seems to be the case because of the implicit type conversion RB usually does between integer and float values. So, how do I tell RB which constructor to call? Top mjh Post subject: Re: Overloading: How do I tell RB which method to use?Posted: Mon Aug 24, 2009 2:08 pm Joined: Sun Feb 19, 2006 3:10 pm Posts: 334 Location: Hamburg, Germany Ford Prefect wrote:Now when I call it, RB says that "There are several items with this name and it is not clear which one the call refers to". This seems to be the case because of the implicit type conversion RB usually does between integer and float values. So, how do I tell RB which constructor to call? This should be unambiguous if you are passing a floating point number; for an integer, an explicit cast such as ânew myClass(UInt32(123))â should do the trick. This is only an issue with literal values (where the compiler has to infer their type); if you are passing a variable, the compile knows its type from its declaration and has no trouble identifying the appropriate method to call. _________________ Michael J. HuÃmann http://digicam-experts.de Top Ford Prefect Post subject: Re: Overloading: How do I tell RB which method to use?Posted: Mon Aug 24, 2009 3:00 pm Joined: Mon Jul 30, 2007 6:11 am Posts: 60 Location: Germany I pass variables, and I get the error anyway. I tried explicit casts, and now I'm a little confused, this is what I get: Code:foo = New className(Double(someOtherClassInstance.somePublicDouble)) The error at this line is now "Type mismatch error. Expected Ptr, but got Double" (the Double keyword in the line is marked). I don't have any idea what's that supposed to mean. (No, the parameter is not ByRef.) Without the explicit cast, I get the error I wrote in my first post. And on another line: Code:foo = New className(UInt32(someInteger)) The error is still the same as in my first post, with and without the explicit typecast. btw, I'm on 2009r3. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
