Reputation: 13
This code worked fine until I added the rot()
function. Yes, it is declared properly in the header file. I replaced all the equation with simple 1.0f values but the same error occurred. That hints to me that it has something to do with declaring Matrix2f rot; ...Does anyone have any clue what the issue is here?
#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;
}
The error the compiler gives:
|17|error: no match for 'operator[]' in 'rot[0]'|
it gives the same code twice for each line from line 17 through line 21... Any help greatly appreciated :)
Upvotes: 1
Views: 52
Reputation: 2350
First of all, you do not need "Matrix2f rot" object inside "rot" method.
You can change your method as:
Vector2f Matrix2f::rot(float theta, Vector2f vec){
float tx = (( cosf(theta) * vec.getX())+( ( -sinf(theta) ) * vec.getY()));
float ty = (( sinf(theta) * vec.getX())+( cosf(theta) * vec.getY()));
return Vector2f(tx, ty);
}
Unless you want to reset the member variable "m" in "rot"( which I assume "float m[2][2]" ) then you can use:
Vector2f Matrix2f::rot(float theta, Vector2f vec){
m[0][0]= cosf(theta); m[0][1]= -sinf(theta);
m[1][0]= sinf(theta); m[1][1]= cosf(theta);
float tx = (( m[0][0] * vec.getX())+( m[0][1] ) * vec.getY()));
float ty = (( m[1][0] * vec.getX())+( m[1][1] * vec.getY()));
return Vector2f(tx, ty);
}
You can not use rot[][] unless your class ( Matrix2f ) provides the implementation which overrides the operator []
Upvotes: 2
Reputation: 1140
You need to access the multidimensional array inside the object which is m. To do this, use rot.m as the multidimensional array.
Upvotes: 0