How to declare arrays from existing class attributes?

It is showing error in array declearations a and b...Any SOLUTIONS??..Assume that i shall do work after array declaration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
using namespace std;
class matrix
{
int rows_1;
int rows_2;
int colums_1;
int colums_2;
	public:
		matrix(): rows_1(0),rows_2(0),colums_1(0),colums_2(0)	
		{	
		}
		void set()
		{int i,j;
			cout<<"Enter the rows of first matrix\n";
			cin>>rows_1;
			cout<<"Enter the rows of second matrix\n";
			cin>>rows_2;
			cout<<"Enter the columns of first matrix\n";
			cin>>colums_1;
			cout<<"Enter the columns of second matrix\n";
			cin>>colums_1;
			cout<<"Enter the elements of first matrix\n";
			for(i=0;i<rows_1;i++)
			{
				for(j=0;j<colums_1;j++)
				{
					cin>>a[i][j];
				}
			}
			cout<<"Enter the elements of second matrix";
			for(i=0;i<rows_2;i++)
			{
				for(j=0;j<colums_2;j++)
				{
					cin>>a[i][j];
				}
			}
		}
		int a[rows_1][colums_1];
		int b[rows_2][colums_2];
};
int main()
{
matrix mult;
mult.set();
mult.mult();
}
Last edited on
If you want an array with size unknown at compile time, you have to create it using new.

You'd be better off just using vectors instead.
I would recommend to store only one matrix per class and create 2 matrix objects in main.
Topic archived. No new replies allowed.