I’m writing a matrix program and am currently trying to multiply a point and a matrix. I keep getting an error over my objects(result and P) “Expression must have pointer to object type” in this function:
//Point Class functions
Point Matrix44::operator*(const Point & P){
Point result;
for (int i = 0; i < 4; i++) {
for (int k = 0; k < 4; k++) {
result.element[i][k] = 0;
for (int j = 0; j < 4; j++) {
result.element[i][k] = element[i][j] * P.element[j][k] + result.element[i][k];
}
}
}
return result;
}
My two classes are:
//Matrix class
class Point;
class Matrix44 {
private:
double element[4][4];
public:
Matrix44(void);
Matrix44 transpose(void) const;
friend istream& operator>>(istream& s, Matrix44& t);
friend ostream& operator<<(ostream& s, const Matrix44& t);
Matrix44 operator *(Matrix44 b);
Point operator*(const Point & P);
};
//Point class
class Point {
double element[4];
friend class Matrix44;
public:
Point(void) {
element[0] = element[1] = element[2] = 0;
element[3] = 1;
}
Point(double x, double y, double z){
element [0]=x;
element [1]=y;
element [2]=z;
element [3]=1;
}
};
In your
Pointclass, you have theelementmember defined as:This is a one-dimensional array. However, in your function, you’re trying to access it as if it were a two-dimensional array:
I think you need to rethink exactly how your matrix multiplication is supposed to work.