title: Matrix class in c++?
body: <p>I've been trying to write a Matrix class and I am using a main method to test it out. It isn't working... at all. </p>
  
  <p>I don't understand why size (the size of allRowValues divided by the size of double) is zero! </p>
  
  <p>I've been writing some debug prints but it isn't helping... I'm really, really new with C++ so ANY and all help / advice will be appreciated. </p>
  
  <pre><code> 1 #include "matrix.h"
   2 #include &lt;iostream&gt;
   3 #include &lt;sstream&gt;
   4 
   5 Matrix::Matrix(){
   6 };
   7 
   8 Matrix::Matrix(int rows, int columns, double allRowValues [] ){
   9     this-&gt;rows = rows;
  10     this-&gt;columns = columns;
  11     this-&gt;matrixValues = new double[rows*columns];
  13     std::cout &lt;&lt;"ALL ROW VALUES" &lt;&lt;std::endl;
  14     std::cout&lt;&lt;"*****" &lt;&lt;std::endl;
  15     std::cout &lt;&lt; sizeof (allRowValues) &lt;&lt; std::endl;
  16     std::cout&lt;&lt;"*****" &lt;&lt;std::endl;
  17     std::cout &lt;&lt; sizeof(allRowValues[0]) &lt;&lt; std::endl;
  18     std::cout&lt;&lt;"*****" &lt;&lt;std::endl;
  19     int size = sizeof(allRowValues)/sizeof(double);
  20     int numberOfValues = rows * columns;
  21     int currentIndex = 0;
  22     for (int i = 0; i &lt; numberOfValues; i++){
  23             std::cout&lt;&lt; "MATRIX CONSTRUCTOR\n";
  24             std::cout&lt;&lt;allRowValues &lt;&lt;std::endl;
  25             std::cout&lt;&lt;"-----"&lt;&lt;std::endl;
  26             std::cout&lt;&lt;index &lt;&lt; std::endl;
  27             std::cout&lt;&lt;"-----"&lt;&lt;std::endl;
  28             std::cout&lt;&lt;size &lt;&lt; std::endl;
  29             std::cout&lt;&lt;"-----"&lt;&lt;std::endl;
  30             if ((allRowValues) &amp;&amp; (currentIndex &lt; size)){
  31                 std::cout &lt;&lt; "ARV " &lt;&lt;std::endl;
  32                 std::cout &lt;&lt; allRowValues[currentIndex] &lt;&lt; std::endl;
  33                 this-&gt;matrixValues[i]= allRowValues[currentIndex];
  34                 std::cout &lt;&lt; "MAT " &lt;&lt; allRowValues[currentIndex++] &lt;&lt; std::endl;
  35             }else{
  36                 std::cout &lt;&lt; "Else\n";
  37             }
  38         }
  39         int index=0;
  40         for (int j = 0; j &lt; rows; j++){
  41             for (int i = 0; i &lt; columns; i++){
  42                 std::cout &lt;&lt; this-&gt;matrixValues[index++];
  43             }
  44             std::cout&lt;&lt;std::endl;
  45         }
  46     };
  47 
  48     Matrix::Matrix(double* rowValues){
  49         int sizeRows = sizeof(rowValues)/sizeof(double);
  50         //TODO: throw error for all rows must be the same length
  51         this-&gt;rows = sizeRows;
  52         int sizeColumns = sizeof(rowValues[0])/sizeof(double);
  53         this-&gt;columns = sizeColumns;
  54         this-&gt;matrixValues = rowValues;
  55     };
  56 
  57     double Matrix::width(){
  58         std::cout &lt;&lt; "Width\n";
  59         return this-&gt;columns;
  60     };
  61 
  62     double Matrix::height(){
  63         std::cout &lt;&lt; "Height\n";
  64         return this-&gt;rows;
  65     };
  66 
  67     std::string Matrix::toString(){
  68         int numberOfValues = 0;
  69         std::cout&lt;&lt;matrixValues[numberOfValues];
  70         std::string build_output;
  71         std::cout&lt;&lt;matrixValues;
  72         for (int i = 0; i &lt; rows; i++){
  73             build_output = "[";
  74             std::cout &lt;&lt; "\n";
  75             for (int j = 0; j &lt; columns; j++){
  76                 std::cout &lt;&lt; "VALUE: " &lt;&lt;matrixValues[numberOfValues];
  77                 build_output = matrixValues[numberOfValues];
  78                 numberOfValues++;
  79             }
  80             build_output = " ]";
  81         }
  82         return build_output;
  83     }
  84 
  85     int main (){
  86         double values[6] = {1, 2, 3, 4, 5, 6};
  87         std::cout &lt;&lt;"Values: \n";
  88         Matrix a = Matrix(2, 3, values);
  89         std::cout &lt;&lt; a.width() &lt;&lt; std::endl;
  90         std::cout &lt;&lt; a.height() &lt;&lt; std::endl;
  91         std::cout &lt;&lt; a.toString();
  92         return 1;
  93 }
  </code></pre>