overloading [][] operators in c++

后端 未结 5 1351
小蘑菇
小蘑菇 2020-12-11 11:39

I\'m writing a matrix 3x3 class in c++.

glm::mat3 provides access to matrix data through the [][] operator syntax.
e.g. myMatrix[0][0] = 1.0f;

5条回答
  •  有刺的猬
    2020-12-11 12:12

    There is no [][] operator. The way GLM does it is by returning a vec3& from the first []. vec3 has its own [] operator overload. So it's two separate operator[]s on two separate classes.

    This is also how GLSL works. The first [] gets the column as a vector. The second takes the vector and gets the value from it.

提交回复
热议问题