Pointer-to-pointer dynamic two-dimensional array

后端 未结 5 1796
庸人自扰
庸人自扰 2020-11-28 03:56

First timer on this website, so here goes..

I\'m a newbie to C++ and I\'m currently working through the book \"Data structures using C++ 2nd ed, of D.S. Malik\".

5条回答
  •  隐瞒了意图╮
    2020-11-28 04:34

    this can be done this way

    1. I have used Operator Overloading
    2. Overloaded Assignment
    3. Overloaded Copy Constructor

      /*
       * Soumil Nitin SHah
       * Github: https://github.com/soumilshah1995
       */
      
      #include 
      using namespace std;
              class Matrix{
      
      public:
          /*
           * Declare the Row and Column
           *
           */
          int r_size;
          int c_size;
          int **arr;
      
      public:
          /*
           * Constructor and Destructor
           */
      
          Matrix(int r_size, int c_size):r_size{r_size},c_size{c_size}
          {
              arr = new int*[r_size];
              // This Creates a 2-D Pointers
              for (int i=0 ;i < r_size; i++)
              {
                  arr[i] = new int[c_size];
              }
      
              // Initialize all the Vector to 0 initially
              for (int row=0; row

提交回复
热议问题