Problem initializing 2D array

Can someone explain to me why I'm getting these two errors? I think it's within the initialization of the 2D arrays. MyInt is a class using dynamic allocation to create an array of single digit integers.

Error in line 5: const MyInt &y expression must have a constant value
Error in line 11: expression must have pointer to object type

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
MyInt operator* (const MyInt& x, const MyInt& y)
{
	MyInt temp;
	temp.Resize((x.size + y.size)+1);
	int *twoDarray= new int [x.size][y.size];

	for(int bottom = 0; bottom < y.size; bottom++ )//controlling the bottom multiplication
		{
			for(int top =0; top < x.size; top++)//controlling top multiplication
			{
				twoDarray[top][bottom] = (x.string[top]*y.string[bottom]);
			}
	    }
	
	int c, r;
	for (c=0; c <=x.size; c ++)
		for( r=0; r<= y.size; r++)
		{
			if(c-r >= 0)
				temp.string[c+r+1] += (twoDarray[c-r][c]);
			else
				r = y.size + 1;
		}
	int over; //for the carry
	for (int j=1; j<temp.size; j++) //carry for multiplication
	{
		if(temp.string[temp.size-j] >=10)
		{
			over= temp.string[temp.size-j]/10;
			temp.string[temp.size-j]%=10;
			if( temp.size-(j+1)<0)
			{
				temp.Resize(temp.size +1);
			}
			temp.string[temp.size-(j+1)]+=over;
		}
	}
	if( temp.string[0] == 0)
	temp.Resize(temp.size -1 );

	return temp;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(){
   //
   //int **p = new int [5][10];  <---- Can't do this
   //

// Can do
   int **p = new int*[5];
   for ( int i(0); i<5;i++)
      p[i] = new int[10];

   for ( int i(0); i<5;i++)
      delete [] p[i];
   delete [] p;
}
Topic archived. No new replies allowed.