我遇到两个编译错误:

/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


我检查以确保所有括号和括号都匹配,但是找不到此问题的根源。您能否看一下我的代码,看看是否误解了?我是c ++的新手,并且主要来自Web编程和脚本编写经验,但是我是一个会做人的学习者,因此请原谅由于没有“阅读我的书”而犯的任何错误,因为我没有本书。简单的解释或指向有关我的失败的更多信息的链接将很有帮助。

调用processVideoFile函数的方式似乎必须存在一些问题,但我无法弄清楚自己做错了什么。感谢您抽出宝贵时间来看看。

main.cpp

    #include <iostream>
#include <stdio.h>
#include <string>
#include <time.h>
#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<string> fileDeque;
    deque<int> fileTimingDeque;



    int exitTrig = -1;
    int counter = 0;

    FILE *MotionIOStream = popen("motion 2>&1", "r");
    if(!MotionIOStream){
      exitTrig = 1;
    }
    while( exitTrig < 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 << "Starting to parse" << endl;
      parseMotionOutput(lineOutput, threadStatus, fileDeque, fileTimingDeque);

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


这是videoProcess.cpp:

#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <boost/xpressive/xpressive_static.hpp>

using namespace boost::xpressive;

int processVideoFiles( std::deque<std::string> &fileDeque, std::deque<int> &fileTimingDeque )
{

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

  int nextFileSeconds = fileTimingDeque.front();
  int diff = secondsNow - nextFileSeconds;
  if( diff > 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/") >> (camDir= ("cam0" >> range('1', '3') >> '/') ) >> (dateDir= ( repeat<4,4>(range('0', '9')) >> '-' >> '0' | '1' >> range( '0', '9' ) >> '/') ) >> (fileName= ( repeat<2,2>(range('0','9')) >> '-' >> repeat<14,14>(range('0','9')) >> '.' >> "avi" ) ) ;
      smatch pathWhat;
      if( regex_search(filePath, pathWhat, pathRegex) )
      {
    std::cout << "The working directory for this file is:" << pathWhat[wd] << std::endl;
    std::cout << "The camera directory for this file is:" << pathWhat[camDir] << std::endl;
    std::cout << "The date directory for this file is:" << pathWhat[dateDir] << std::endl;
    std::cout << "The filename of this file is:" << pathWhat[fileName] << std::endl;
      }else
      {
    std::cout << "Error: Couldn't match the file path regex." << 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 << "Couldn't create jpeg files for some reason" << endl;
      }else
      {
    return 0;
      }

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

最佳答案

似乎您忘记了在类声明后的某个位置放置;,或忘记了放置匹配的}。该错误很可能出现在您未显示的头文件之一中。

10-08 05:41
查看更多