I'm trying to learn about linear algebra through a book and the author leaves a code block for a basic struct for Vector3D. I understand everything except for the two blocks with float& operator and const float& operator. Is it possible if I could get an in depth explanation of the code here?
I've attempted to google the usage of operators which makes those two blocks of code seem like some sort of implicit conversion is happening, but I'm still at a loss for everything else.
#include <iostream>
using namespace std;
//Math Engine
struct Vector3D
{
float x, y, z;
Vector3D(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
Vector3D() = default;
float& operator [](int i)
{
return ((&x)[i]);
}
const float& operator [](int i) const
{
return ((&x)[i]);
}
};
int main()
{
return 0;
}