U
undbund
Hi, i am learing how to create a multidimensional dynamic array.I want
to initialize the array in the constructor. I have tried looking for
the solution in this news group but none of them were helpful.
Here is the code:
#include <iostream>
#include <conio>
using namespace std;
class Mat
{
int (*mat)[3][3];
public:
Mat::Mat();
void printArray();
};
Mat::Mat()
{
(*mat)[3][3] = new int[3][3];
for( int r = 0; r < 3; r++ )
{
for( int c = 0; c < 3; c++ )
{
(*mat)[r][c] = r * 2;
}
}
}
void Mat:rintArray()
{
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 3; j++ )
{
cout << mat[j] << " ";
}
cout << endl;
}
}
int main()
{
Mat m;
m.printArray();
getch();
return 0;
}
I get the following error:
Error E2034 D:\programming\matrix.cpp 16:
Cannot convert 'int ( *)[3]' to 'int' in function Mat::Mat()
How to solve this error?
thanks for any help
undbund
to initialize the array in the constructor. I have tried looking for
the solution in this news group but none of them were helpful.
Here is the code:
#include <iostream>
#include <conio>
using namespace std;
class Mat
{
int (*mat)[3][3];
public:
Mat::Mat();
void printArray();
};
Mat::Mat()
{
(*mat)[3][3] = new int[3][3];
for( int r = 0; r < 3; r++ )
{
for( int c = 0; c < 3; c++ )
{
(*mat)[r][c] = r * 2;
}
}
}
void Mat:rintArray()
{
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 3; j++ )
{
cout << mat[j] << " ";
}
cout << endl;
}
}
int main()
{
Mat m;
m.printArray();
getch();
return 0;
}
I get the following error:
Error E2034 D:\programming\matrix.cpp 16:
Cannot convert 'int ( *)[3]' to 'int' in function Mat::Mat()
How to solve this error?
thanks for any help
undbund