13.1.8.4 Member Functions

In addition to the accessor and modifiers, the following member functions are generated for an OMG IDL union of type TYPE with switch (long) discriminator:

TYPE ();
This is the default constructor for a union. No default discriminator is set by this function, so you cannot access the union until you set the value of the union.
TYPE( const TYPE&From);
This copy constructor deep copies the specified union. Any data in the union parameter is copied. The From argument specifies the union to be copied.
~TYPE();
This destructor frees the data associated with the union.
TYPE &operator=(const TYPE &From);
This assignment operator copies the specified union. Any existing value in the current union is freed. The From argument specifies the union to be copied.
void _d (CORBA::Long Discrim);
This modifier function sets the value of the union discriminant. The Discrim argument specifies the new discriminant. The data type of the argument is determined by the OMG IDL data type specified in the switch statement of the union. For each OMG IDL data type, see the following table for the C++ data type.
Only use this function to set the discriminant to a value within the same union member. You cannot use this function to implicitly switch between different union members.
These restrictions are illustrated by the following code:
union U switch(long) {
case 1:
case 2:
short s;
case 3:
int it;
};

short st;
U u;
u.s(1296); // member "s" selected
st = u.s(); // st == 1296
u._d(2); // OK: member "s" still selected
st = u.s(); // st == 1296
u._d(3); // BAD_PARAM: selecting a different member
When the _d() modifier is invoked on a new instance of a union, Tuxedo C++ relaxes the "implicit switching" restriction. In this case, no exception is thrown, and the union is not affected.
U u2;
u2._d(1);     // no exception, union is unchanged
st = u2.s(); // error! accessing an uninitialized union
u2.it(1296); // OK: member "it" now selected
CORBA::Long _d () const;
This function returns the current discriminant value. The data type of the return value is determined by the OMG IDL data type specified in the switch statement of the union. For each OMG IDL data type, see the following table for the C++ data type.