【发布时间】:2011-09-14 21:52:02
【问题描述】:
我正在编写一个矩阵程序,目前正在尝试将一个点和一个矩阵相乘。我的对象(结果和 P)在此函数中不断出现错误“表达式必须具有指向对象类型的指针”:
//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;
}
我的两个班级是:
//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;
}
};
【问题讨论】: