I want the vector constructor file gain access to all private or protected members in the matrix header file so that I can multiply matrix and vector by overloading the * operator in the constructor file.
Even though I changed the private to protected in Matrix header file, and let Vector header file inherit everything in the Matrix file, yet I somehow can't access all its private or protected members,
this is the private member class for the Matrix header file for Matrix.h:
class Matrix
{
private:
int Rows;
int Cols;
int Index = Rows * Cols;
std::vector<std::vector<float>> cell;
...
this is constructor code for the * operator overloading inside Vector.cpp file
Vector operator*(const Matrix &matrix, const Vector &vector){
Vector vec(0.0, 0.0, 0.0);
for (int i = 0; i < matrix.Cols; i++){
for (int m = 0; m < vector.Index; m++) {
vec.element[i]+=matrix.cell[i][m]*vector.element[m];
}
}
return vec;
}
the problem lies with that I cant access to all matrices, private members, even though I declared the vector as a friend as matrix and even I turned private to protected members:
this means that the vector should inherit everyting the Matrix has right?
class Vector: public Matrix
{
...
}
and I did change to private to protected, but it still gave me the same result.
the result should be
v2:[47.62
132.644
18.5]
the error messages are:
Matrix::Cols: cannot access protected member declared in class 'Matrix' vector.cpp
Matrix::cell: cannot access protected member declared in class 'Matrix' vector.cpp
how does vector.cpp file access all matrix.h's private members?
and I don't want to turn private into public otherwise my code will become a pile of unrecogisable mess.
Aucun commentaire:
Enregistrer un commentaire