I was looking through the source of OpenDE and I came across some wierd syntax usage of the operator[] on a class. Here's a simplified example to show the syntax:
#include <iostream>
class Point
{
public:
Point() : x(2.8), y(4.2), z(9.5) {}
operator const float *() const
{
return &x;
}
private:
float x, y, z;
};
int main()
{
Point p;
std::cout << "x: " << p[0] << '\n'
<< "y: " << p[1] << '\n'
<< "z: " << p[2];
}
Output:
x: 2.8
y: 4.2
z: 9.5
What's going on here? Why does this syntax work? The operator[] for Point isn't overloaded in anyway and here this code is trying to do an automatic conversion to float somewhere. I've never seen this kind of usage before and it looks unusual to me.
Thanks