how to modify 2d array in function c++
void Insert_into_2D_Array(int** foo, int x_pos, int y_pos, int x_size, int y_size)
{
int insert_value = 10;
if (x_pos < x_size && y_pos < y_size) {
foo[x_pos][y_pos] = insert_value; // insert_value lost post func exit?
}
}
void Init_2D_Array(int** foo, int x_size, int y_size)
{
foo = new int*[x_size]; // new alloc mem lost post func exit ?
for (int i=0;i
how to modify 2d array in function c++
class Array2D
{
private:
int* m_array;
int m_sizeX;
int m_sizeY;
public:
Array2D(int sizeX, int sizeY) : m_sizeX(sizeX), m_sizeY(sizeY)
{
m_array = new int[sizeX*sizeY];
}
~Array2D()
{
delete[] m_array;
}
int & at(int x, int y)
{
return m_array[y*sizeX + x];
}
};
how to modify 2d array in function c++
void Insert_into_2D_Array(int** foo, int x_pos, int y_pos, int x_size, int y_size)
{
int insert_value = 10;
if (x_pos < x_size && y_pos < y_size) {
foo[x_pos][y_pos] = insert_value; // insert_value lost post func exit
}
}
int** Init_2D_Array(int x_size, int y_size)
{
int** foo = new int*[x_size]; // new alloc mem lost post func exit
for (int i = 0; i
how to modify 2d array in function c++
void Insert_into_2D_Array(int** foo, int x_pos, int y_pos, int x_size, int y_size)
{
int insert_value = 10000;
if (x_pos < x_size && y_pos < y_size) {
(foo)[x_pos][y_pos] = insert_value; // insert_value lost post func exit
}
}
void Init_2D_Array(int*** foo, int x_size, int y_size)
{
*foo = new int*[x_size]; // new alloc mem lost post func exit
for (int i=0;i
|