title: How to pass several objects to a function as parameter in c++
body: <p>I have a class as below that its method accept an object as its parameter.</p>
  
  <pre><code>template &lt;typename T&gt; class Matrix{
  private:
      matrixNode&lt;T&gt;* rear=0;
      std::vector&lt;int&gt; rows;
      std::vector&lt;int&gt; cells;
      std::vector&lt;matrixNode&lt;T&gt;*&gt; listofAddedNodes;
      void generatetableRowCellArrays(int rowSize,int cellSize){
          for (int i=0;i&lt;rowSize;i++){
              rows.push_back(i);
          }
          for (int i=0;i&lt;cellSize;i++){
              cells.push_back(i);
          }
      }
  public: 
      Matrix(int rowSize,int cellSize){
          generatetableRowCellArrays(rowSize,cellSize);
      }
  
      void ceateSparsMatrix(matrixNode&lt;T&gt; *node){
          matrixNode&lt;T&gt; *mxNode=(matrixNode&lt;T&gt;*)malloc(sizeof(matrixNode&lt;T&gt;));
          mxNode=node;
  
          if(rear!=0){
             rear-&gt;PL=(matrixNode&lt;T&gt;*)&amp;rows[mxNode-&gt;line];
             rear-&gt;PC=(matrixNode&lt;T&gt;*)&amp;cells[mxNode-&gt;column];
          }
  
          rear=mxNode;
  
          listofAddedNodes.push_back(mxNode);
      }
  
      void ceateSparsMatrix(matrixNode&lt;T&gt; node,int SpecificRow,int specificCell){
          matrixNode&lt;T&gt; *mxNode=(matrixNode&lt;T&gt;*)malloc(sizeof(matrixNode&lt;T&gt;));
          mxNode=node;
          if(rear!=0){
             rear-&gt;PL=&amp;rows[SpecificRow];
             rear-&gt;PC=&amp;cells[specificCell];
          }
          rear=mxNode;
          listofAddedNodesPointers.push_back(&amp;rear-&gt;value);
      }
  
      void showAllAddedNodes(){
          for(int i=0;i&lt;listofAddedNodes.size();i++){
              printf("|----------------------------|\n");
              printf("|Value   | %d                 |\n",listofAddedNodesPointers[i]-&gt;value);
              printf("|Coll    | %d                 |\n",listofAddedNodesPointers[i]-&gt;column);
              printf("|Line    | %d                 |\n",listofAddedNodesPointers[i]-&gt;line);
              printf("|PC      | %d        |\n",listofAddedNodesPointers[i]-&gt;PC);
              printf("|PL      | %d        |\n",listofAddedNodesPointers[i]-&gt;PL);
              printf("|----------------------------|\n");
  
          }
      }};};
  </code></pre>
  
  <p>When i want to test this function , i create several objects of the "matrixNode" class and pass to the function but it doesn't work! </p>
  
  <pre><code>Matrix&lt;int&gt; matrix(5,6);
  
    matrixNode&lt;int&gt; *matNode();
    matNode-&gt;column=2;
    matNode-&gt;line=0;
    matNode-&gt;value=2;
    matNode-&gt;PC=NULL;
    matNode-&gt;PL=NULL;
  
    matrixNode&lt;int&gt; *matNode2;
    matNode2-&gt;column=5;
    matNode2-&gt;line=5;
    matNode2-&gt;value=5;
    matNode2-&gt;PC=NULL;
    matNode2-&gt;PL=NULL;
  
   matrix.ceateSparsMatrix(matNode);
   matrix.ceateSparsMatrix(matNode2);
  </code></pre>
  
  <p>It doesn't pass the objects well! 
  Can you please help me?
  Thanks</p>