This is wrong code and does not work at all. It gives an error like:
PVSS00ui (0), 2011.06.20 10:30:04.602, IMPL, WARNING, 50, Default branch called, MappingVar, operator=, cannot assign variable of type TEXT_VAR
(I have discussed the code with some folks here at Croon. We feel it is not the best way the code this. The problem solved this way is the adding of a new key with a value of the type mapping.
This can also be achieved by passing the adres of the mapping and the new key as parameters to foo().
But currently the code seems to work just fine. From your reaction i get the feeling it will not do so in the future releases of PVSS. That's why i posted this on the forum.)
Huh ?
Your original post did include a different script than the one currently shown above ... did you change it later on ?
My reply was based on your initial code:
main()
{
mapping p;
foo(p);
DebugN(p);
}
foo(mapping& x )
{
x = "impliciet";
}
foo tries to assign a string to the complete mapping, which is not possible, therefore the error.
Your (changed) code from above now works without error
Calling foo(p["xxx"]);
Indexing a mapping with a key which does not exist yet will produce a new entry in the mapping with that key
containing an empty mixed as its value.
Hi Martin,
If you look at my first code snippet it call foo with p["xxx"]. Which does not yet exists, because "xxx" is not yet used.
My second post is first creating p["xxx"] by assigning an empty string. That gives me the same error as you mentioned in your first answer.
You confirm that my first code snippet actually works.
Does this also mean it is a valid way of programming? Is it working this way by design?