c++: issue with main()? - a function-declaration is not allowed here before '{' token
<p>I'm getting two compile errors:</p>

<pre><code>/home/sater/projects/MotionManager/videoProcess.cpp:11:1: error: a function-definition is not allowed here before ‘{’ token
/home/sater/projects/MotionManager/main.cpp:85:1: error: expected ‘}’ at end of input
</code></pre>

<p>I checked to make sure that all parentheses and brackets were matched, but can't find the root of this problem.  Could you please take a look at my code to see if I'm misunderstanding something?  I'm new to c++ and am coming from mostly web programming and scripting experience but I'm a learn by doing sort of person so please excuse any mistakes due to not having "read my book" because I don't have one.  A simple explanation or link to more information about my failure would be helpful.</p>

<p>It seems like there must be some problem in the way I call the processVideoFile function, but I can't figure out what I did wrong.  Thanks for spending the time to take a look.</p>

<p>main.cpp</p>

<pre><code>    #include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;time.h&gt;
#include "parseMotion.cpp"
#include "resumepause.cpp"
#include "videoProcess.cpp"

using namespace std;

bool DEBUG = true;

int main(int argc, char **argv) {
    //Useful directory strings
    string camDir [3];
    camDir[0]= "cam01(Outside)/";
    camDir[1]= "cam02(Upper)/";
    camDir[2]= "cam03(Lower)/";

    string latestWD = "/Store/SecurityStorage/LatestVideos/";
    string archiveWD = "/Store/SecurityStorage/VideoArchive/";

    int threadStatus [3];
    threadStatus[0] = 0;
    threadStatus[1] = 0;
    threadStatus[2] = 0;
    //-50 paused
    //-1 couldn't connect initially to camera
    //0 Not yet started
    //1 Started successfully
    //2 lost connection to cam - retrying

    deque&lt;string&gt; fileDeque;
    deque&lt;int&gt; fileTimingDeque;



    int exitTrig = -1;
    int counter = 0;

    FILE *MotionIOStream = popen("motion 2&gt;&amp;1", "r");
    if(!MotionIOStream){
      exitTrig = 1;
    }
    while( exitTrig &lt; 0 )
    {      
      //Set maximum length, fgets: get one line
      char buffer[1024]; 
      string lineOutput;
      lineOutput = fgets(buffer, sizeof(buffer), MotionIOStream);

      //check mysqldb for pause/resume
      int rpResult;
      rpResult = checkSchedule(threadStatus);
      if(rpResult != 0)
      {
    return rpResult;
      }

      //process video - fork
      int pid;
      pid = processVideoFiles(fileDeque, fileTimingDeque);
      if(pid == 0)
      {
    return 0;
      }

      //cout &lt;&lt; "Starting to parse" &lt;&lt; endl;
      parseMotionOutput(lineOutput, threadStatus, fileDeque, fileTimingDeque);

      counter++;
      //[3] Thread 3 started
      if( counter &gt; 20 )
      {
    exitTrig = 2;
    pclose(MotionIOStream);
    system("killall motion");
    return 0;
      }
    }
    //Handle error returns here.
    //case 1: "Couldn't start motion."
    //case 2: ""
    return 0;
}
</code></pre>

<p>Here is videoProcess.cpp:</p>

<pre><code>#include &lt;string&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;boost/xpressive/xpressive_static.hpp&gt;

using namespace boost::xpressive;

int processVideoFiles( std::deque&lt;std::string&gt; &amp;fileDeque, std::deque&lt;int&gt; &amp;fileTimingDeque )
{

  std::time_t secondsNow;
  secondsNow = std::time(NULL);

  int nextFileSeconds = fileTimingDeque.front();
  int diff = secondsNow - nextFileSeconds;
  if( diff &gt; 120)
  {
    //Should fork
    int pid = fork();
    if(pid == 0){
      //Is child
      std::string filePath = fileDeque.front();
      mark_tag wd(1), camDir(2), dateDir(3), fileName(4);
      // /Store/SecurityStorage/LatestVideos/cam03(Lower)/2011-07-21/01-20110721112236.avi
      sregex pathRegex =  (wd= "/Store/SecurityStorage/LatestVideos/") &gt;&gt; (camDir= ("cam0" &gt;&gt; range('1', '3') &gt;&gt; '/') ) &gt;&gt; (dateDir= ( repeat&lt;4,4&gt;(range('0', '9')) &gt;&gt; '-' &gt;&gt; '0' | '1' &gt;&gt; range( '0', '9' ) &gt;&gt; '/') ) &gt;&gt; (fileName= ( repeat&lt;2,2&gt;(range('0','9')) &gt;&gt; '-' &gt;&gt; repeat&lt;14,14&gt;(range('0','9')) &gt;&gt; '.' &gt;&gt; "avi" ) ) ;
      smatch pathWhat;
      if( regex_search(filePath, pathWhat, pathRegex) )
      {
    std::cout &lt;&lt; "The working directory for this file is:" &lt;&lt; pathWhat[wd] &lt;&lt; std::endl;
    std::cout &lt;&lt; "The camera directory for this file is:" &lt;&lt; pathWhat[camDir] &lt;&lt; std::endl;
    std::cout &lt;&lt; "The date directory for this file is:" &lt;&lt; pathWhat[dateDir] &lt;&lt; std::endl;
    std::cout &lt;&lt; "The filename of this file is:" &lt;&lt; pathWhat[fileName] &lt;&lt; std::endl;
      }else
      {
    std::cout &lt;&lt; "Error: Couldn't match the file path regex." &lt;&lt; std::endl;
    return 0;
      }

      //mplayer $filepath -vo jpeg -ao null -frames 25
      std::string commandString = "mplayer " + filePath + " -vo jpeg -ao null -frames 25";
      const char* commandChar = commandString.c_str();

      int commandResult = system(commandChar);
      if(commandResult != 0)
      {
    std::cout &lt;&lt; "Couldn't create jpeg files for some reason" &lt;&lt; endl;
      }else
      {
    return 0;
      }

      //Last steps
      fileDeque.pop_front();
      fileTimingDeque.pop_front();
    }
      return pid;
  }else
  {
    return 1;
  }
}
</code></pre>
