Now, the problem. The this-vector has a few objects in it. What I want to do is make an Example variable and make the Data* point to the first member of the this-vector. I thought about making something like this:
Example doesnotwork = {"", 0};
doesnotwork.data = this.at(0);
Oops, didn't think of that, but that's not the issue. I simply made up all the variable names for the sake of the example as I don't have the code at the moment.
typedefunion Data{
int m;
double u;
long f;
Data(int kj, double lh, long fg)
{
m = kj;
u = lh;
f = fg;
}
Data& operator= (const Data& mydat)
{
m = mydat.m;
u = mydat.u;
f = mydat.f;
return *this;
}
};
Why are you using a union, isn't this undefined behavior?
I have to say, I've never seen a union written that way.
But it looks like undefined behavior to me as well, because for a union you can only access one "member" at a time, after you've previously written to it. If you write a member then read another, it might blow up.