c++ - How to copy anonymous union -


i have anonymous union in struct

struct {   union {     char c;     double d;   };   a(const &a) {     c = a.c;     d = a.d;   } }; 

i wondering best way define copy constructor. have copy union fields? guess have ...?

remember 1 union field @ time can active. copy union, need copy whichever 1 of them active.

generally, when using unions this, you'll have sort of "tag" field keeping track of field active. can use switch statement on tag determine field active 1 , how copy over.

alternatively, consider using boost::variant, type-safe wrapper around object of 1 of fixed number of types.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -