title: not declared in scope c++
body: <p>I am getting an error that breed is not declared in scope even though it is right below the fucntion. What is wrong?</p>
  
  <p>The exact error is: prog.cpp: In function ‘void best(std::string*)’:
  prog.cpp:131:15: error: ‘breed’ was not declared in this scope
   breed(bestRats)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  #include &lt;math.h&gt;
  #include &lt;map&gt;
  #include &lt;string.h&gt;
  #include &lt;queue&gt;
  #include &lt;regex&gt;
  #include &lt;bitset&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;climits&gt;
  // #include "dungeonrats.cpp"
  
  using namespace std;
  
  /*
  Finds the maximum integer in an array of integers.
  Size is the size of the given array.
  */
  int getMax(int* numbers, int size) {
     int maximum = INT_MIN;
     for (int i = 0; i &lt; size; i++) {
        if (numbers[i] &gt; maximum) maximum = numbers[i];
     }
     return maximum;
  }
  
  int getMaxi(int* numbers, int size) {
     int maximum = INT_MIN;
     int maxi;
     for (int i = 0; i &lt; size; i++) {
        if (numbers[i] &gt; maximum) {
           maximum = numbers[i];
           maxi = i;
        }
     }
     return maxi;
  }
  
  
  /*
  "randomly" generates a new maze (but is it REALLY random?)
  aim is 65% empty tiles
  10% food tiles
  10% obstacles
  15% pits
  */
  string getNewMaze(string mapseed) {
     string maze = mapseed.substr(6); // get everything except the 25:25:
     for (int i = 0; i &lt; 626; i++) {
        int percentile = rand() % 100; // from 0 to 99
        if (percentile &lt; 65) {
           maze[i] = '.';
        }
        else if (percentile &gt;= 65 &amp;&amp; percentile &lt; 75) {
           maze[i] = '$';
        }
        else if (percentile &gt;= 75 &amp;&amp; percentile &lt; 85) {
           maze[i] = '*';
        }
        else maze[i] = 'X';
  
     }
  
  
  
     return maze;
  }
  
  /*
  A function used to print how many of each kind of tile
  exist in the maze.
  */
  void testFrequency(string mapseed) {
     int numEmpty = 0;
     int numFood = 0;
     int numObs = 0;
     int numPit = 0;
     for (int i = 0; i &lt; 626; i++) {
        if (mapseed[i] == '.') {
           numEmpty++;
        }
        if (mapseed[i] == '$') {
           numFood++;
        }
        if (mapseed[i] == '*') {
           numObs++;
        }
        if (mapseed[i] == 'X') {
           numPit++;
        }
     }
     cout &lt;&lt; "Number of empty tiles is " &lt;&lt; numEmpty &lt;&lt; endl;
     cout &lt;&lt; "Number of food tiles is " &lt;&lt; numFood &lt;&lt; endl;
     cout &lt;&lt; "Number of obstacles is " &lt;&lt; numObs &lt;&lt; endl;
     cout &lt;&lt; "Number of pits is " &lt;&lt; numPit &lt;&lt; endl;
  
  
  }
  
  /*
  Returns an array of size 2 containing the best two rats.
  */
  void best(string r[]) {
     // r is the array of five rat genomes
     //int moves = simulator(mapseed, genome, start_row, start_col);
     int* ratMoves = new int[5]; // array that stores how long each rat lasted
     int maxIndex = 0;
     int max = INT_MIN;
     string originalMapseed = "25:25:..$.$.X.............X....$X.X*..X$..X...*X$..$...X$.$......X.$.X...XX.$.X*.*.*..X..X.**.......X..$$$...........XX.....................$...X...*.$..X..$X..........$.*..X.....$.X..$*.$X......$...X.*X$......$.**.X.X..XX$X..*....*..X.X....$...X...X........$.X....$...*...X$*........X..$*$$......$$...$*..X.$.$......$.$.$...$..X.*.....X..$......$.XX*..X.$.X......X$*.**.....X*...$..XX..X.....$....X....X...X....X.$X$..X..........$...*.X$..X...$*...........*....XXX$$.$.$..*$XX..XX..*.....$......X.XX$..$$..X$.XX.$$..X.*..*......X......$..$.$$..*...X.........$X....$X.$$.*.$.$.$..**.....X.$.$X.*.$.........$**..X.X.X$X.$.*X.X*..$*.";
  
     for (int i = 0; i &lt; 5; i++) {
        string mapseed = getNewMaze(originalMapseed);
        int sumTurns = 0;
        for (int k = 0; k &lt; 10; k++) {
           string mapseed = getNewMaze(originalMapseed);
           // sumTurns += simulator(mapseed,r[i],12,12); // uncomment this line once in correct file
        }
        ratMoves[i] = sumTurns / 10; // average of rat's performance
                                     // over 10 random maps
        if (ratMoves[i] &gt; max) { // find the best
           max = ratMoves[i];
           maxIndex = i;
        }
  
     }
     string bestRats[2];
     bestRats[0] = r[maxIndex]; // store the best
     ratMoves[maxIndex] = INT_MIN; // remove the best from array of rat moves
     bestRats[1] = r[getMaxi(ratMoves, 5)]; // get the second best &amp; store it
     breed(bestRats);
  
  }
  
  void breed(string r[]) {
     int cap = 10;
     string c[5];
     for (int j = 0; j&lt;5; j++)
        for (int i = 0; i&lt;190; i++) {
           int check = rand() % cap + 1;
           if (check % 2 == 0) {
              if (check == 0)
                 c[j] += rand() % 81 + 42;
              else
                 c[j] += r[1][i];
           }
           else
              c[j] += r[0][i];
        }
     best(c);
  }
  int main() {
     string c[5];
     for (int j = 0; j&lt;5; j++)
        for (int i = 0; i&lt;190; i++)
           c[j] += rand() % 81 + 42;
     best(c);
  }
  </code></pre>