fxm wrote: ↑Nov 02, 2022 22:24
- Finally, a little sophistication with the code to take advantage of it to validate some capabilities versus this nested structure:
And again, I did not push the sophistication to the extreme here above, because I then found thus a bug when I wanted to add a copy-constructor.
See:
BUG : Illicit "error 202: Illegal member access, UDT.operator.cast" compiler error message
A patchwork of the bugged compiler error messages for a structure with a Nested Name Type.
With indirect conversions:
- cast() operator + conversion-constructor() matching between them, instead of directly the dedicated constructor(),
- cast() operator + the let() operator matching between them, instead of directly the dedicated let() operator.
Code: Select all
Type TU
Public:
Type TV
Public:
Dim As String sv
Declare Constructor()
' Private:
Declare Operator Cast() As String
End Type
Dim As TV iv
Declare Constructor()
' Declare Constructor(Byref v As TV)
Declare Constructor(Byref s As String)
Declare Constructor(Byref s As String, Byval n As Integer)
' Declare Operator Let(Byref v As TV)
Declare Operator Let(Byref s As String)
Declare Sub s1(Byval u As TU)
Declare Function f1() As TU
Declare Function f2() As TU
End Type
Constructor TU()
Print "Constructor TU()"
End Constructor
'Constructor TU(Byref v As TV)
' Print "Constructor TU(Byref As TV)"
' This.iv.sv = v.sv
'End constructor
Constructor TU(Byref s As String)
Print "Constructor TU(Byref s As String)"
This.iv.sv = s
End Constructor
Constructor TU(Byref s As String, Byval n As Integer)
Print "Constructor TU(Byref As String, Byval As Integer)"
For I As Integer = 1 To n
This.iv.sv &= s
Next I
End constructor
'Operator TU.Let(Byref v As TV)
' Print "Operator TU.Let(Byref As TV)"
' This.iv.sv = v.sv
'End Operator
Operator TU.Let(Byref s As String)
Print "Operator TU.Let(Byref As String)"
This.iv.sv = s
End Operator
Constructor TU.TV()
Print "Constructor TV()"
End Constructor
Operator TU.TV.Cast() As String
Print "Operator TV.Cast() As String"
Return This.sv
End operator
Sub TU.s1(Byval u As TU)
This = u
End Sub
Function TU.f1() As TU
Return This.iv
End function
Function TU.f2() As TU
Function = This.iv
End function
Dim As TU.TV v
Print
Dim As TU u = v
Print
u = v
Print
u.s1(v)
Print
u.f1()
Print
u.f2()
Print
Sleep
Code: Select all
Constructor TV()
Operator TV.Cast() As String
Constructor TV()
Constructor TU(Byref s As String)
Operator TV.Cast() As String
Operator TU.Let(Byref As String)
Operator TV.Cast() As String
Constructor TV()
Constructor TU(Byref s As String)
Operator TV.Cast() As String
Constructor TV()
Constructor TU(Byref s As String)
Constructor TV()
Constructor TU()
Operator TV.Cast() As String
Operator TU.Let(Byref As String)
If The cast() operator is private -> normal
compiler error messages:
Code: Select all
Type TU
Public:
Type TV
Public:
Dim As String sv
Declare Constructor()
Private:
Declare Operator Cast() As String
End Type
Dim As TV iv
Declare Constructor()
' Declare Constructor(Byref v As TV)
Declare Constructor(Byref s As String)
Declare Constructor(Byref s As String, Byval n As Integer)
' Declare Operator Let(Byref v As TV)
Declare Operator Let(Byref s As String)
Declare Sub s1(Byval u As TU)
Declare Function f1() As TU
Declare Function f2() As TU
End Type
Constructor TU()
Print "Constructor TU()"
End Constructor
'Constructor TU(Byref v As TV)
' Print "Constructor TU(Byref As TV)"
' This.iv.sv = v.sv
'End constructor
Constructor TU(Byref s As String)
Print "Constructor TU(Byref s As String)"
This.iv.sv = s
End Constructor
Constructor TU(Byref s As String, Byval n As Integer)
Print "Constructor TU(Byref As String, Byval As Integer)"
For I As Integer = 1 To n
This.iv.sv &= s
Next I
End constructor
'Operator TU.Let(Byref v As TV)
' Print "Operator TU.Let(Byref As TV)"
' This.iv.sv = v.sv
'End Operator
Operator TU.Let(Byref s As String)
Print "Operator TU.Let(Byref As String)"
This.iv.sv = s
End Operator
Constructor TU.TV()
Print "Constructor TV()"
End Constructor
Operator TU.TV.Cast() As String
Print "Operator TV.Cast() As String"
Return This.sv
End operator
Sub TU.s1(Byval u As TU)
This = u
End Sub
Function TU.f1() As TU
Return This.iv
End function
Function TU.f2() As TU
Function = This.iv
End function
Dim As TU.TV v
Print
Dim As TU u = v
Print
u = v
Print
u.s1(v)
Print
u.f1()
Print
u.f2()
Print
Sleep
C:\.....\FBIDETEMP.bas(67) error 202: Illegal member access, TU.TV.operator.cast in 'Return This.iv'
C:\.....\FBIDETEMP.bas(71) error 202: Illegal member access, TU.TV.operator.cast in 'Function = This.iv'
C:\.....\FBIDETEMP.bas(75) error 202: Illegal member access, TU.TV.operator.cast in 'Dim As TU u = v'
C:\.....\FBIDETEMP.bas(78) error 202: Illegal member access, TU.TV.operator.cast in 'u = v'
C:\.....\FBIDETEMP.bas(81) error 202: Illegal member access, TU.TV.operator.cast at parameter 1 (u) of S1() in 'u.s1(v)'
With direct assignment added to the existing code:
+ dedicated constructor(),
+ dedicated let() operator.
=> cast() operator no longer called.
Code: Select all
Type TU
Public:
Type TV
Public:
Dim As String sv
Declare Constructor()
' Private:
Declare Operator Cast() As String
End Type
Dim As TV iv
Declare Constructor()
Declare Constructor(Byref v As TV)
Declare Constructor(Byref s As String)
Declare Constructor(Byref s As String, Byval n As Integer)
Declare Operator Let(Byref v As TV)
Declare Operator Let(Byref s As String)
Declare Sub s1(Byval u As TU)
Declare Function f1() As TU
Declare Function f2() As TU
End Type
Constructor TU()
Print "Constructor TU()"
End Constructor
Constructor TU(Byref v As TV)
Print "Constructor TU(Byref As TV)"
This.iv.sv = v.sv
End constructor
Constructor TU(Byref s As String)
Print "Constructor TU(Byref s As String)"
This.iv.sv = s
End Constructor
Constructor TU(Byref s As String, Byval n As Integer)
Print "Constructor TU(Byref As String, Byval As Integer)"
For I As Integer = 1 To n
This.iv.sv &= s
Next I
End constructor
Operator TU.Let(Byref v As TV)
Print "Operator TU.Let(Byref As TV)"
This.iv.sv = v.sv
End Operator
Operator TU.Let(Byref s As String)
Print "Operator TU.Let(Byref As String)"
This.iv.sv = s
End Operator
Constructor TU.TV()
Print "Constructor TV()"
End Constructor
Operator TU.TV.Cast() As String
Print "Operator TV.Cast() As String"
Return This.sv
End operator
Sub TU.s1(Byval u As TU)
This = u
End Sub
Function TU.f1() As TU
Return This.iv
End function
Function TU.f2() As TU
Function = This.iv
End function
Dim As TU.TV v
Print
Dim As TU u = v
Print
u = v
Print
u.s1(v)
Print
u.f1()
Print
u.f2()
Print
Sleep
Code: Select all
Constructor TV()
Constructor TV()
Constructor TU(Byref As TV)
Operator TU.Let(Byref As TV)
Constructor TV()
Constructor TU(Byref As TV)
Constructor TV()
Constructor TU(Byref As TV)
Constructor TV()
Constructor TU()
Operator TU.Let(Byref As TV)
But with the cast() operator declared private, illicit
compiler error messages are obtained:
Code: Select all
Type TU
Public:
Type TV
Public:
Dim As String sv
Declare Constructor()
Private:
Declare Operator Cast() As String
End Type
Dim As TV iv
Declare Constructor()
Declare Constructor(Byref v As TV)
Declare Constructor(Byref s As String)
Declare Constructor(Byref s As String, Byval n As Integer)
Declare Operator Let(Byref v As TV)
Declare Operator Let(Byref s As String)
Declare Sub s1(Byval u As TU)
Declare Function f1() As TU
Declare Function f2() As TU
End Type
Constructor TU()
Print "Constructor TU()"
End Constructor
Constructor TU(Byref v As TV)
Print "Constructor TU(Byref As TV)"
This.iv.sv = v.sv
End constructor
Constructor TU(Byref s As String)
Print "Constructor TU(Byref s As String)"
This.iv.sv = s
End Constructor
Constructor TU(Byref s As String, Byval n As Integer)
Print "Constructor TU(Byref As String, Byval As Integer)"
For I As Integer = 1 To n
This.iv.sv &= s
Next I
End constructor
Operator TU.Let(Byref v As TV)
Print "Operator TU.Let(Byref As TV)"
This.iv.sv = v.sv
End Operator
Operator TU.Let(Byref s As String)
Print "Operator TU.Let(Byref As String)"
This.iv.sv = s
End Operator
Constructor TU.TV()
Print "Constructor TV()"
End Constructor
Operator TU.TV.Cast() As String
Print "Operator TV.Cast() As String"
Return This.sv
End operator
Sub TU.s1(Byval u As TU)
This = u
End Sub
Function TU.f1() As TU
Return This.iv
End function
Function TU.f2() As TU
Function = This.iv
End function
Dim As TU.TV v
Print
Dim As TU u = v
Print
u = v
Print
u.s1(v)
Print
u.f1()
Print
u.f2()
Print
Sleep
C:\.....\FBIDETEMP.bas(67) error 202: Illegal member access, TU.TV.operator.cast in 'Return This.iv'
C:\.....\FBIDETEMP.bas(71) error 202: Illegal member access, TU.TV.operator.cast in 'Function = This.iv'
C:\.....\FBIDETEMP.bas(75) error 202: Illegal member access, TU.TV.operator.cast in 'Dim As TU u = v'
C:\.....\FBIDETEMP.bas(78) error 202: Illegal member access, TU.TV.operator.cast in 'u = v'
C:\.....\FBIDETEMP.bas(81) error 202: Illegal member access, TU.TV.operator.cast at parameter 1 (u) of S1() in 'u.s1(v)'