Adding elements to dynamic array

Hi, I want to add some elements to an n*n array that the user specifies at the beginning. However, I'm getting a C2540 and C2440 error. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
double tridiagonal(){
	int i, j, mainlength,answerlength;
	double *a;
	cout <<"Enter n*n matrix size";
	cin >> mainlength;
	a= new double [mainlength][mainlength];

	for(i=0; i<mainlength; i++){
		for(j=0; j<mainlength; j++){
			cin >> new a[i][j];
		}
	}
        //DO WHATEVER HERE
	delete[] a;
}
What do you mean by "add elements"? Your code seems attempt to "set the value" of existing elements.


See http://www.cplusplus.com/articles/G8hv0pDG/
Topic archived. No new replies allowed.