Answers for "union syntax in c++"

C++
1

union cpp

union S
{
    std::string str;
    std::vector<int> vec;
    ~S() {} // needs to know which member is active, only possible in union-like class 
};          // the whole union occupies max(sizeof(string), sizeof(vector<int>))
 
Posted by: Guest on June-02-2021

Browse Popular Code Answers by Language