Can someone please figure out the problems in this code for me. I am using code blocks 17.12. I am trying to make a Matrix class in which i want to initialize a matrix using a constructor and after then get the members of the array using a function. And then overload the '*' operator to multiply two entered matrices. And then overload the ostream to show the already given matrix as input or the product(like "cout<< m<< endl;).
#include <iostream>
using namespace std;
class Matrix
{
private:
//static int row; //don't work
//static const int row; //don't work
//constexpr int row; //don't work
int row;
int column;
//Here my moto is to make a matrix which takes input from the user and
create the matrix of desired size at runtime.
double A[row][column];
public:
Matrix(int row,int column);
Matrix(Matrix &mat);
void setRowXColumn(int row,int column);
void setColumn(int column);
void setMatrix(Matrix A);
};
int main()
{
//Here 3 and 2 are the rows and columns of the matrix m respectively.
Matrix m(3,2);
return 0;
}
Matrix::Matrix(int row=0,int column=0)
{
setRowXColumn(int row,int column); //error: expected primary-expression before 'int'|
//what primary-expression?
}
Matrix::Matrix(Matrix &mat)
{
row=mat.row;
column=mat.column;
}
void Matrix::setRowXColumn(int row,int column)
{
if(row<0)
this->row=0;
else
this->row=row;
if(column<0)
this->column=0;
else
this->column=column;
}
//And i also want the members as input by the user at runtime.
void Matrix::setMatrix(Matrix A)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
cout<<"Enter"<<Matrix A<<"["<<i<<"]"<<"["<<j<<"]"<<endl;
cin>>A[i][j];
}
}
}
From the above code i am getting the following errors.
||=== Build: Debug in Class Matrix (compiler: GNU GCC Compiler) ===|
Class Matrix\main.cpp|9|error: invalid use of non-static data member 'Matrix::row'|
Class Matrix\main.cpp|7|note: declared here|
Class Matrix\main.cpp|9|error: invalid use of non-static data member 'Matrix::column'|
Class Matrix\main.cpp|8|note: declared here|
Class Matrix\main.cpp||In constructor 'Matrix::Matrix(int, int)':|
Class Matrix\main.cpp|42|error: expected primary-expression before 'int'|
Class Matrix\main.cpp|42|error: expected primary-expression before 'int'|
Class Matrix\main.cpp||In member function 'void Matrix::setMatrix(Matrix)':|
Class Matrix\main.cpp|69|error: expected primary-expression before 'A'|
Class Matrix\main.cpp|70|error: no match for 'operator[]' (operand types are 'Matrix' and 'int')|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
I totally appreciate your help and thank you. I am a student an currenty learning c++. I am still working on this code.
Edit:-So far i have reduced the errors but "double A[row][column] is the main headache to me. I want it like this because i want to create a matrix like what i did in the main function. And then take the members of array as input next. Hope this edit clarifies my question further.
Thank you...