title: how to pass 2d array object to function in c++?
body: <p>I have a 2D fixed size object array of "spot" class
  Spot map[row][col];//row &amp; col are dynamic changed integer
  I want to pass it to a function
  bool isFilled(int row,int col,Spot[row][col]){}
  How to define the function? How to delete this array ?Please see my code. Thanks for your help.</p>
  
  <pre><code>Spot.h
  
      #ifndef SPOT_H
  #define SPOT_H
  
  class Spot
  {
  private:
      bool isBunny;
      int nextCycle;
  public:
      static const int UP = 0;
      static const int RIGHT = 1;
      static const int DOWN = 2;
      static const int LEFT = 3;
      static const int SLEEP = 4;
  
      virtual void setSpot(bool newIsBunny);
      Spot();
      ~Spot();
      virtual int getNextCycle();
      virtual void setNextCycle();
      virtual bool getIsBunny();
      virtual void makeBunny();
  };
  
  void Spot::setSpot(bool newIsBunny)
  {
      isBunny = newIsBunny;
      nextCycle = UP;
  }
  
  Spot::Spot()
  {
      isBunny = false;
      nextCycle = UP;
  }
  
  Spot::~Spot()
  {
  }
  
  void Spot::setNextCycle()
  {
      if (nextCycle != SLEEP)
      {
          nextCycle++;
      }
  }
  
  int Spot::getNextCycle()
  {
      return nextCycle;
  }
  
  bool Spot::getIsBunny()
  {
      return isBunny;
  }
  
  void Spot::makeBunny()
  {
      if (!isBunny)
          nextCycle = UP;
      isBunny = true;
  }
  
  
  #endif  /* SPOT_H */
  
  
  Bunny.cpp
  
  
  
  #include "Spot.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;vector&gt;
  #include &lt;boost/algorithm/string.hpp&gt;
  
  
  using namespace std;
  
  
  static string line;
  static ifstream inFile;
  static ofstream outFile;
  bool isFilled(int x, int y, Spot **myMap);
  
  int main () {
    int numSims = 0;
    inFile.exceptions ( ifstream::failbit | ifstream::badbit );
  
    try {
      inFile.open ("/home/mike/Desktop/input.txt");
      outFile.open ("/home/mike/Desktop/output.txt");
     // while(!inFile.eof())
        {
  
           getline (inFile,line);
          numSims= atoi(line.c_str());
         //cout&lt;&lt;"numSims: "&lt;&lt;numSims&lt;&lt;endl;
          for (int i = 0;i &lt; numSims;i++)
              {
                  int minPerCycle = 1;
                  getline (inFile,line);
                  minPerCycle= atoi(line.c_str());
  
              //cout &lt;&lt; "minPerCycle: "&lt;&lt;minPerCycle &lt;&lt;endl;
  
                  int row = 0;
                  int col = 0;
                      getline (inFile,line);
                      std::vector&lt;std::string&gt; xy;
                      boost::split(xy, line, boost::is_any_of(" "));
                      row=atoi(xy.at(0).c_str());
                      col=atoi(xy.at(1).c_str());
                      //cout &lt;&lt;"row: "&lt;&lt; row&lt;&lt;endl;
                      //cout &lt;&lt; "col: "&lt;&lt;col&lt;&lt;endl;
  
  
                      Spot** myMap = new Spot* [col];
                      for(int i = 0; i &lt; col; ++i)
                          myMap[i] = new Spot [row];
  
                      //std::vector&lt;std::vector&lt;Spot&gt; &gt; myMap(x, std::vector&lt;Spot&gt;(y));
                      for (int i = 0;i &lt; row;i++)
                              {
                                  getline (inFile,line);
                                  //cout&lt;&lt;line&lt;&lt;endl;
                                  for (int j = 0;j &lt; col;j++)
                                  {
                                      if (line[j] == 'B')
                                      {
                                          myMap[i][j].setSpot(true);
  
                                      }
                                      else
                                      {
                                          myMap[i][j].setSpot(false);
  
                                      }
                                  }
                              }
                  int numCycles = 1;
  
                  if (isFilled(row,col,myMap))
                  {
                      numCycles = 0;
                  }
  
                  while (!isFilled(row,col,myMap))
                  {
                      numCycles++;
  
                      for (int j = 0;j &lt; row;j++)
                      {
                          for (int k = 0;k &lt; col;k++)
                          {
                              if (myMap[j][k].getIsBunny())
                              {       //cout&lt;&lt; j&lt;&lt;" "&lt;&lt;k&lt;&lt;" " &lt;&lt;"true"&lt;&lt;endl;
                                      switch (myMap[j][k].getNextCycle())
                                      {
                                          case Spot::UP :
                                              if (j&gt;0)
                                              myMap[j-1][k].makeBunny();
                                              break;
                                          case Spot::RIGHT :
                                              if (k&lt;col-1)
                                              myMap[j][k + 1].makeBunny();
                                              break;
                                          case Spot::DOWN :
                                              if (j&lt;row-1)
                                              myMap[j+ 1][k].makeBunny();
                                              break;
                                          case Spot::LEFT :
                                              if (k&gt;0)
                                              myMap[j][k - 1].makeBunny();
                                              break;
                                      }
                                      myMap[j][k].setNextCycle();
                                  }
                              //cout&lt;&lt; j&lt;&lt;" "&lt;&lt;k&lt;&lt;" " &lt;&lt;"outside"&lt;&lt;endl;
                          }
                      }
  
                  }
                  int time = numCycles*minPerCycle;
                  outFile&lt;&lt;"It took " &lt;&lt;time &lt;&lt;" minutes for the bunnies to take over the world!\n";
                  cout&lt;&lt;"It took " &lt;&lt;time &lt;&lt;" minutes for the bunnies to take over the world!\n";
                  for(int i=0; i &lt; col; i++) {
                     delete [] myMap[i];
                  }
                  delete myMap;
  
              }
        }
  
         inFile.close();
         outFile.close();
  
  }
    catch (ifstream::failure e) {
      cout &lt;&lt; "Exception opening/reading file";
    }
  
    return 0;
  }
  
  
  bool isFilled(int row, int col,Spot **myMap)
  {
      for (int i = 0;i &lt; row;i++)
      {
          for (int j = 0;j &lt; col;j++)
          {
              if (!myMap[i][j].getIsBunny())
              {
                  //cout&lt;&lt;"true ";
                  return false;
  
              }
              //else
              //  cout&lt;&lt;"false ";
  
  
          }
          //cout&lt;&lt;endl;
  
      }
      return true;
  }
  </code></pre>