You are using a version without Ads of this website. Please, consider donating:

### syntax and type specification errors

I am getting multiple "missing ';' before '*' , and "type specifier - int assumed" errors on only two lines of code (all errors are in the header files).

line 23:
vector2 operator*(const matrix &rhs);

line 31:
vector2 operator*(const vector2 &rhs);

The following are the header files:

matrix.h
 1234567891011121314151617181920212223242526272829303132 #ifndef MATRIX_H #define MATRIX_H #include "vector2.h" #include class matrix { public: double mat[3][3]; matrix(); matrix multiply_scalar(double s); matrix transpose_matrix(); double det_matrix(); matrix inverse_matrix(); matrix cofactor_matrix(); //operator overloads matrix operator+(const matrix &rhs); matrix operator*(const matrix &rhs); vector2 operator*(const vector2 &rhs); // ** ERRORS ** // matrix transformations void makeRotation(double r); void makeScale(double x, double y); void makeTranslate(double x, double y); }; #endif

vector2.h
 12345678910111213141516171819202122232425262728293031323334 #ifndef VECTOR2_H #define VECTOR2_H #include "matrix.h" #include class vector2{ public: double x,y; vector2(); vector2(float xval, float yval); // overloaded operators vector2& operator=(const vector2 &rhs); vector2 operator-=(const vector2 &rhs); vector2 operator+=(const vector2 &rhs); vector2 operator*=(const float rhs); vector2 operator-(const vector2 &rhs); vector2 operator*(const float rhs); // scale vector2 operator+(const vector2 &rhs); double operator* (const vector2 &rhs); // dot product float magnitude(); void scale(float); void normalize(); vector2 operator*(const matrix &rhs); // ** ERRORS ** }; #endif

I have thoroughly combed the entire program and there are no missing ;.

Does anyone have a suggestion for fixing these errors?
On line 16 in vector2.h why is there an & after the vector2?
Last edited on
I think that the problem is that you included the both headers inside each other.

matrix.h
 12345 #ifndef MATRIX_H #define MATRIX_H #include "vector2.h" #include

vector2.h
 12345 #ifndef VECTOR2_H #define VECTOR2_H #include "matrix.h" #include

Why are you declaring an overloading operator for vector2 inside of the header file matrix.h? I'm not sure that's workable.(line 23 matrix.h)

also, and sorry, I haven't played much with operator overloading, but can you actually set one up to multiply two objects from separate classes? (line 31 vector2.h)

Since both those lines are causing errors and they seem suspicious ...
Last edited on
@newbieg "On line 16 in vector2.h why is there an & after the vector2?"

Because in the vector2.cpp I am returning the address of the rhs.
 1234567 vector2& vector2::operator=(const vector2 &rhs) { x = rhs.x; y = rhs.y; return *this; }

The reason the headers are inside eachother are so I can multiply a vector by matrix and vica versa in the respected .cpp's (shown below). Removing either headers from within eachother doubles the amount of errors, leaving the original errors untouched.

vector.cpp
 12345678910111213141516171819202122232425 vector2 vector2::operator*(const matrix &rhs) { double temp[3]; temp[0] = 0; temp[1] = 0; temp[2] = 1; double tempV[3]; tempV[0] = x; tempV[1] = y; tempV[2] = 1; for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) { temp[i] += rhs.mat[i][j] * tempV[j]; } vector2 temp2; temp2.x = temp[0]; temp2.y = temp[1]; return temp2; }

and matrix.cpp
 123456789 vector2 matrix::operator*(const vector2 &rhs) { vector2 temp; temp.x=rhs.x*mat[0][0]+rhs.y*mat[0][1]+mat[0][2]; temp.y=rhs.x*mat[1][0]+rhs.y*mat[1][1]+mat[1][2]; return temp; }

Thank you for your speedy responses! I will continue to work on this and in the mean time, I appreciate any and all suggestions.
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: