1
Next, we embed the unrestricted union in a surrounding aggregate: tt(class
2
Data). The aggregate is provided with an tt(enum Tag), declared in its public
3
section, so tt(Data)'s users may request tags. tt(Union) itself is for
4
tt(Data)'s internal use only, so tt(Union) is declared in tt(Data)'s private
5
section. Using a tt(struct Data) rather than tt(class Data) we start out
6
in a public section, saving us from having to specify the initial tt(public:)
7
section for tt(enum Tag):
23
~Union(); // no actions
24
// ... to do: declarations of members
32
tt(Data)'s constructors receive tt(int) or tt(string) values. To pass these
33
values on to tt(d_union), we need tt(Union) constructors for the various union
34
fields; matching tt(Data) constructors also initialize tt(d_tag) to proper
37
Data::Union::Union(int value)
41
Data::Union::Union(std::string const &str)
46
Data::Data(std::string const &str)