I have a union, defined like so:
union CellType {
std::string str;
int i;
double d;
Money<2> m; // Custom class for fixed-decimal math.
};
Then, I have a vector of such unions.
std::vector<CellType> csvLine;
My question is, how do I append a value to the end of the vector? I normally use push_back for vectors of strings, ints, etc., but can't quite figure out the syntax when the vector elements are unions. Any help would be appreciated.
(Yes, this class is reading CSV files a line at a time, if that makes any difference.)
here is failing MRE
#include <vector>
#include <iostream>
union CellType {
std::string str;
int i;
double d;
// Money<2> m; // Custom class for fixed-decimal math.
};
int main() {
std::vector<CellType> csvLine;
CellType c;
c.str = "foo";
csvLine.push_back(c);
}
Money commented out because because irrelevant to the MRE
Error
Severity Code Description Project File Line Suppression State Error C2280 'CellType::CellType(void)': attempting to reference a deleted function ConsoleApplication1 C:\work\ConsoleApplication1\ConsoleApplication1.cpp 22