Without modifying the code already existing, only insert your own code (one line is sufficient here) under the matching comment so that the program works as requested:
Code: Select all
Type UDT Extends Object
Public:
Declare Function checkAddr (Byval pu As Any Ptr) As String
Private:
Declare Operator @ () As Any Ptr
Dim As Any Ptr dummy
End Type
Function UDT.checkAddr (Byval pu As Any Ptr) As String
If pu = Cast(Byte Ptr, @This.dummy) - Offsetof(UDT, dummy) Then
Return "Good address"
Else
Return "Bad address"
End If
End Function
Dim As UDT u
Dim As Any Ptr p
' Other lines of code and allocations may follow here
'p = @u ' error 201: Illegal member access, UDT.operator.@
'
' Insert below the right code to assign the address of u to p
' so that calling u.checkAddr(p) returns "Good address"
'--------------------- Begin insertion ----------------------
'---------------------- End insertion -----------------------
Print u.checkAddr(p)
Sleep
- Code of member function checkAddr() improved from a dodicat's proposal.