1

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 :)

2
  • looks to be rot.m[0][0] ? Commented Jul 17, 2014 at 16:54
  • Show us the overload of operator[] in Matrix2f. That's certainly the problem. Commented Jul 17, 2014 at 17:04

2 Answers 2

2

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 []

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it appears I over complicated the whole process.
0

You need to access the multidimensional array inside the object which is m. To do this, use rot.m as the multidimensional array.

1 Comment

But the constructor should take care of that on its own. In this case, any matrix declared initializes as the identity matrix. I'm not crating multidimensional array of multidimensional arrays.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.