dimanche 20 janvier 2019

Forcing c++ compiler to accept a cast

I want to use something similar to

union {
     char c[sizeof(std::string)];
     std::string string_; 
} UnionString;

inside:

class foo {
    int indicator;
    UnionString str;
}

where the indicator holds the true type (holds other info but it can also be used for this). Want to add a c'tor with char* and a c'tor std::string. Is there a way to do this without boost::variant or boost::any ?

Aucun commentaire:

Enregistrer un commentaire