How can I define an operatpr [] for this class ?
#include <iostream>
using namespace std;
class Vec4 {
float f1,f2,f3,f4;
public:
Vec4(float ff1, float ff2, float ff3, float ff4): f1(ff1), f2(ff2), f3(ff3), f4(ff4) {}
float operator [] (int index)
{
}
Vec4 operator + (const Vec4& v)
{
return Vec4(f1 + v.f1, f2 + v.f2, f3 + v.f3, f4 + v.f4);
}
Vec4 operator - (const Vec4& v)
{
return Vec4(f1 - v.f1, f2 - v.f2, f3 - v.f3, f4 - v.f4);
}
Vec4 operator * (const Vec4& v)
{
return Vec4(f1 * v.f1, f2 * v.f2, f3 * v.f3, f4 * v.f4);
}
Vec4 operator / (const Vec4& v)
{
return Vec4(f1 / v.f1, f2 / v.f2, f3 / v.f3, f4 / v.f4);
}
Vec4& operator = (const Vec4& v)
{
f1 = v.f1;
f2 = v.f2;
f3 = v.f3;
f4 = v.f4;
return *this;
}
Vec4 operator += (const Vec4& v)
{
return Vec4(f1 += v.f1, f2 += v.f2, f3 += v.f3, f4 += v.f4);
}
Vec4 operator -= (const Vec4& v)
{
return Vec4(f1 -= v.f1, f2 -= v.f2, f3 -= v.f3, f4 -= v.f4);
}
Vec4 operator *= (const Vec4& v)
{
return Vec4(f1 *= v.f1, f2 *= v.f2, f3 *= v.f3, f4 *= v.f4);
}
Vec4 operator /= (const Vec4& v)
{
return Vec4(f1 /= v.f1, f2 /= v.f2, f3 /= v.f3, f4 /= v.f4);
}
friend ostream& operator << (ostream& os, const Vec4& v)
{
return os << v.f1 << " " << v.f2 << " " << v.f3 << " " << v.f4 << endl;
}
};
int main()
{
Vec4 v(1,2,3,4);
Vec4 w(11,22,33,44);
Vec4 z = v + w;
cout << z;
}