I was wondering about having a method return an r-value. Specifically, I was wondering if there was a way to do this with an overloaded operator. I have this code:
struct vec4 {
float x;
float y;
float z;
float w;
...
inline float operator [] (int i)
{
switch (i) {
case 0:
return this->x;
case 1:
return this->y;
case 2:
return this->z;
case 3:
return this->w;
default:
exit(1);
return 0;
}
}
};
How can I change this so that I could use something to the effect of
vec4 v;
...
v[2] = 5.0f;
I've hear about rvalue references in C++11, and could they be a potential solution?
EDIT: I found a way to put in my actual code.