#include <iostream>
#include <new>
usingnamespace std;
class matrix {
public: int **matrice;
int n, i, j, rand, col;
matrix(int, int);
};
matrix::matrix(int rand, int col) {
matrice = newint*[rand];
for (i = 0; i < rand; i++)
matrice[rand] = newint[col];
for (i = 0; i < rand; i++)
for (j = 0; j < col; j++)
{
cout << "randul " << i + 1 << " coloana " << j + 1 << " = ";
cin >> *(*(matrice + i) + j);
}
}
int main()
{
matrix a(2, 2);
return 0;
}
When I run it, I get some exceptions after I read the first value of the array. An "Access violation writing location 0xCDCDCDCD". And I have no ideea why...
I just added a simple function to my class to print the arrays I read. But it seems that the arrays disappear after the constructor done its job.
This is the function:
1 2 3 4 5 6
void matrix::print_m() {
for (i = 0; i < rand; i++)
{
for (j = 0; j < col; j++)
cout << matrice[i][j] << ' ';
cout << endl;
And if I do this:
1 2
matrix a(2,2);
a.print_m();
after i fill the array, nothing happens; it doesnt get printed.Any ideeas why?