document: Using constructed types in C++ unions The C++ Standard states that a union type can not have a member with a nontrivial constructor or destructor . While at first this seems unreasonable , further thought makes it clear why this is the case : The crux of the problem is that unions do n't have built-in semantics for denoting when a member is the `` current '' member of the union . Therefore , the compiler ca n't know when it 's appropriate to call constructors or destructors on the union members . Still , there are good reasons for wanting to use constructed object types in a union . For example , you might want to implement a scripting language with a single variable type that can either be an integer , a string , or a list . A union is the perfect candidate for implementing such a composite type , but the restriction on constructed union members may prevent you from using an existing string or list class -LRB- for example , from the STL -RRB- to provide the underlying functionality . Luckily , a feature of C++ called placement new can provide a workaround
doc_bio_tags: O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O
extractive_keyphrases: union type constructors destructors union members scripting language placement new
abstractive_keyphrases: c++ standard