I have a bit of code somewhat like this:
class Token{
public:
union tester{
double literal;
string name;
tester(double op) : literal(op) {};
tester(string val) : name(val) {};
tester(): tester(0.0) {};
};
void setUp(){
//the literal and name members of tester should be initialized here
};
/*other functions are below, two of which require that the values of literal
and name can be changed*/
};
I need to initialize both the literal and name members, but I'm not sure how. I have tried making a variable of type tester and doing this: tester test(45.0);, but then I can only set one of the member variables, and simply using tester(45.0); doesn't work either I tried this: Token thing; thing.name = "Elly", that didn't work. My class doesn't use constructors either. So, my questions are, how can I set and then later change the values of the member variables in tester in Token?
I am using the C++11 compiler.
(I apologize in advance if this question has been answered already or is too silly, I have been looking around, but I really don't understand how I can get this to work. I'm missing something, but I'm not quite sure what.)