【发布时间】:2014-09-08 15:54:55
【问题描述】:
在我添加 rot() 函数之前,这段代码运行良好。是的,它在头文件中正确声明。我用简单的 1.0f 值替换了所有方程,但发生了同样的错误。这向我暗示它与宣布 Matrix2f 腐烂有关。 ...有没有人知道这里的问题是什么?
#include "Matrix2f.h"
#include <cmath>
#include <iostream>
#include "Vector2f.h"
Matrix2f::Matrix2f(){
m[0][0]= 1.0f; m[0][1]= 0.0f;
m[1][0]= 0.0f; m[1][1]= 1.0f;
}
Vector2f Matrix2f::rot(float theta, Vector2f vec){
Matrix2f rot;
rot[0][0]= cosf(theta); rot[0][1]= -sinf(theta);
rot[1][0]= sinf(theta); rot[1][1]= cosf(theta);
float tx = ((rot[0][0]*vec.getX())+(rot[0][1]*vec.getY()));
float ty = ((rot[1][0]*vec.getX())+(rot[1][1]*vec.getY()));
return Vector2f(tx, ty);
}
void Matrix2f::printMat(){
std::cout << "| " << m[0][0] << " " << m[0][1] << " |" << std::endl;
std::cout << "| " << m[1][0] << " " << m[1][1] << " |" << std::endl;
}
编译器给出的错误:
|17|error: no match for 'operator[]' in 'rot[0]'|
它为从第 17 行到第 21 行的每一行给出两次相同的代码... 非常感谢任何帮助:)
【问题讨论】:
-
看起来是 rot.m[0][0] ?
-
向我们展示
operator[]在Matrix2f中的重载。这肯定是问题所在。
标签: c++ multidimensional-array compiler-errors operators