|Pliant talk forum
Discussion: union-like for type
Continuation of an old discussion about union-like
constructions for type
|Message posted by pom on 2002/05/10 07:32:38
|The problem arised by a union-like construction for types concerns the
creation and the destruction of the union.
There may be a simple way to avoid these problems:
1/ have a "selector" field which value corresponds to the currently used
member of the union (by default the first of the union, or the member taged
"default"). Only this member is built at the object creation.
2/ have a method to change the selctor. On selector change, the destroy
is called on the old member and the build is called on the new one
3/ have a copy which calls the selector change on the target when necessary
4/ the destroy destroys the currently selected member.
|Message posted by maybe Hubert Tonneau on 2002/05/10 10:54:52
|We'd better have a pointer to the current type in the union, and have the
access method to various union fields change the current type (and do the
required 'destroy' and 'build' whenever required).
We simply need to handle the case where all possible types for the union are
scalar: in such a case, just drop the pointer to the current type, and all