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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef MATRIX_H
#define MATRIX_H

#include "vector2.h"
#include <cmath>

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef VECTOR2_H
#define VECTOR2_H

#include "matrix.h"
#include <cmath>

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?
Thank you in advance for your time and advice.
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
1
2
3
4
5
#ifndef MATRIX_H
#define MATRIX_H

#include "vector2.h"
#include <cmath> 



vector2.h
1
2
3
4
5
#ifndef VECTOR2_H
#define VECTOR2_H

#include "matrix.h"
#include <cmath> 

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.
1
2
3
4
5
6
7
vector2& vector2::operator=(const vector2 &rhs)
{
	x = rhs.x;
	y = rhs.y;

	return *this;
}


@vlad from moscow

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
1
2
3
4
5
6
7
8
9
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.