On May 5, 2007, at 2:40 AM, kev wrote:

> RB2007r2, PowerBook G4 1.5ghz
>
>
> I seem to be having an issue with overriding operator_convert.
>
> Here's some code to try to explain:
>
> I have 2 classes, one is a subclass of the other:
>
>
> class SuperClass
>
>       Sub operator_convert(s as string)
>               MsgBox "SuperClass operator_convert"
>       End Sub
>
>
>
>       Sub MyMethod()
>               MsgBox "SuperClass MyMethod"
>       End Sub
>
> End Class
>
>
> class SubClass
>
>       Sub operator_convert(s as string)
>               MsgBox "SubClass operator_convert"
>       End Sub
>
>
>
>       Sub MyMethod()
>               MsgBox "SubClass MyMethod"
>       End Sub
>
> End Class
>
>
> // This code is in the App.Open event
>
> Sub Open()
>
>    dim myClass as SuperClass
>
>    myClass = new SubClass     // Debugger says myClass is a SubClass
>
>    myClass.MyMethod           // calls Subclass.MyMethod as expected
>
>    myClass = "hello world"    // calls SuperClass.operator_convert ?!?!
>                               // now Debugger says myClass is a SuperClass!

This is exactly what I would expect.  What's happening is that the  
compiler sees the assignment of a String to a variable of type  
Class1.  It then looks for an Operator_Convert subroutine with  
parameter of type String, which it finds.  So it creates a new Class1  
object and calls Operator_Convert.

That myClass was not nil prior to the execution of this line does not  
matter.


Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to