fxm wrote:When the Cast operator returns by reference, conversion can be bidirectional (but not implicit in the reverse direction)
Unfortunately, if this is not documented, I dont know anyone even in the advanced users that would think of writting:
Cast(Integer, u2) = J
I myself wont be able to recall something that I don't find readable enough, or really hardly. If a macro could do:
InverseCast(u2, Integer)
based on Cast_byref, it would be a serious helper.
But I guess you are too much advanced to find interesting to mention the simplest facts that we meet first. But look again to this:
Code: Select all
type UDT
as integer i
end type
dim as UDT u
u = Cast(UDT, 99)
The error is not "missing explicit operator cast...", it's "type mismatch". That doesn't help. If anyway the common beginner find the page on operator cast, he will get stuck immediately:
Code: Select all
declare operator Cast(as integer) as UDT 'doesn't exist and ignored
declare operator Cast() as ?? 'nothing of this form will work for fixing the present case
declare operator Cast() byref as integer 'if could work, I'm not even sure despite example above, should be anyway very very well explained in detail , syntax is quite uncommon
So from the documentation point of view. First thing to complete seems to me to say clearly 2 things:
▪ at cast page, that there are a world of features dedicated to udts. So at present day this page is quite omitting a crucial information for no reason (the page is very small and wouldn't be flooded with a tiny remark about datatypes)
▪ at operator cast page. Should be also said clearly that Cast(UDT, var) requires a special treatment. As the example above showed, the need of operator cast starts even if the user doesn't have to use a complex udt. So for the user that is just interested on cast, he should find if possible the answer (return byref?) or be directed without delay to more stuff. For the moment, a beginner wont find the solution to the simple problem exposed above.
Maybe the fact that the documentation is in english is also why I dont really like to read more than the header with usage and syntax. That's why I would prefer that any question about datatype parameter of Cast would be mentioned there.
Maybe some feedback from other users would help however. For I'm no more able to read the doc page as a pure beginner when I read the explanations from the forum simultaneously. But before I posted, I was in a real life user situation. Question on syntax due to error, jump to doc. Answer not found so posting here. When I find the informations I generally won't ask for more (for the simple reason that I don't think of more, like advanced usage).
Cast page
By using a member Operator Cast, Cast can be overloaded for a user defined type expression.
I just have seen this more recent addition. Just a problem. What if the user don't identify its problem in term of overloading an operator of an udt (or he would already be reading operator cast). This could be clearer if saying that the datatypes divide in famillies, built-in and udt. The key problem is in the datatype limitation.