我正在用c ++编写矩阵3x3类.
glm :: mat3通过[][] operator
语法提供对矩阵数据的访问.
例如,myMatrix[0][0] = 1.0f;
将第一行,第一列输入设置为1.0f.
我想提供类似的访问权限.怎么能超载[][] operator
s?
我尝试了以下内容,但是我收到了错误:
必须将运算符名称声明为函数
const real operator[][](int row, int col) const
{
// should really throw an exception for out of bounds indices
return ((row >= 0 && row <= 2) && (col >= 0 && col <= 2)) ? _data[row][col] : 0.0f;
}
Run Code Online (Sandbox Code Playgroud)
重载此运算符的正确方法是什么?