I am writing a simple header file that can make a dynamic 2d array and put 0 in the row and col, print the array, and delete the array.
In Debug when stepping through, the 2d array gets initialized, it puts 0 in there, however when my_array.Print_Array(); called, the compiler skips it.
when i try to print the array from the main file it fails. any help would be appreciate it.
HEADER FILE:
class twoD_Array
{
public:
int **Array;
int *col, *row;
int size_col, size_row;
twoD_Array(int, int);
~twoD_Array();
void Print_Array();
};
twoD_Array::twoD_Array(int size_c, int size_r)
{
size_col = size_c;
size_row = size_r;
Array = new int *[size_col];
for (int i = 0; i < size_col; i++)
{
Array[i] = new int[size_row];
for (int j = 0; j < size_row; j++)
Array[i][j] = 0;
}
}
void twoD_Array::Print_Array()
{
for (int y_i = 0; y_i<size_col; y_i++)
{
for (int x_i = 0; x_i<size_col; x_i++)
std::cout << Array[y_i][x_i];
std::cout << std::endl;
}
}
twoD_Array::~twoD_Array()
{
for (int i = 0; i < size_row; i++)
delete[] Array[i];
delete[] Array;
}
Main File:
#include "stdafx.h"
#include <iostream>
#include "2D_Array.h"
int main()
{
int x, y;
std::cout << "how many x variables?" << std::endl;
std::cin >> x;
std::cout << "how many y variables?" << std::endl;
std::cin >> y;
twoD_Array my_array(x, y);
my_array.Print_Array();
return 0;
}