anybody can help with this piece of code;
I am using class to build matrices nut when I define my object it says the default constructor does not exist. how can I fix it?
Thanks in advance
when I define my object it says the default constructor does not exist. how can I fix it?
Either:
(1) write a default constructor (one with no arguments);
or
(2) match your statement in main() to the constructor that you have supplied (takes two ints as parameters);
or
(3) give the parameters in the current constructor some default values (e.g. Matrix::Matrix(int rows=1, int cols=1)
You either need to construct your matrix with the correct number of parameters, and you really should declare the no argument constructor (the "default" constructor) as deleted.
Do you mean, how do you set the values of the individual array elements?
Either make vals public and access vals[i], or, you could do something like overload the () operator and let it have (row, column) input arguments.
As you're not allowing the size to be changed, then the size can only be specified in the constructor. Hence a default constructor is only really valid if it defines a default sized matrix. Consider:
Actually I want to use this class to produce the local and global stifness matrix in finite element method and the size should be chargeable. And also I want to pass another argument in the class which is the area of each element. The area of each element is obtained by a struct. Since I'm very new in objective oriented programming this gonna be hard for me at this time. I don't know hot to pass an argument within a class which is coming from another class or struct.