我正在研究矩阵运算,外出的老师为我们提供了这3个下一个功能:
//methods used as GETTERS and SETTERS - to access the matrix elements
float& mat3::at(int i, int j) {
return matrixData[i + 3 * j];
}
const float& mat3::at(int i, int j) const {
return matrixData[i + 3 * j];
}
mat3& mat3::operator =(const mat3& srcMatrix) {
//usage example for the "at" getter/setter methods
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
//at(i,j) acts as a setter
//srcMatrix.at(i, j) is used as a getter
at(i, j) = srcMatrix.at(i, j);
}
}
return (*this);
}
我知道'srcMatrix.at(i,j)'起着吸气剂的作用,这很明显,因为该功能会返回该位置的值。但是我不明白为什么它也充当设置者,没有分配。哪个“ at”功能是吸气剂,哪个是setter?
在您的帖子中,最重要的两个函数是吸气剂,而第三个是setter。要了解原因,请仔细查看以下行: