title: Fork() and Wait() in C++
body: <p>I have a class in C++ that calls fork() and then wait()s for the child process to get done, but I get a compiler error when I try to do it.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  /* Connection class */
  class Connection {
      string destination, userName, computerName;
  
  public:
      /*  constructor for class
      You must pass it two strings. The first must be either the word "server" or the word "client".
      This will tell us which machine we want to connect to. The second will specify the username
      with which to connect to that machine.
      */
      Connection(string state, string user="default_username")
      {
          if(state == "server")
          {
              cout &lt;&lt; "You've chosen to connect to the 'server'.\n";
              destination = "user.palmetto.clemson.edu:";
              userName = user;
              cout &lt;&lt; "Destination: " &lt;&lt; destination &lt;&lt; ", Username: " &lt;&lt; userName &lt;&lt; "\n";
              cout &lt;&lt; "Full connect argument: " &lt;&lt; userName &lt;&lt; "@" &lt;&lt; destination &lt;&lt; "\n";
          } else if (state == "client")
          {
              cout &lt;&lt; "You've chosen to connect to the 'client'.\n";
              destination = "NIElaparo.ces.clemson.edu:";
              userName = user;
              cout &lt;&lt; "Destination: " &lt;&lt; destination &lt;&lt; ", Username: " &lt;&lt; userName &lt;&lt; "\n";
              cout &lt;&lt; "Full connect argument: " &lt;&lt; userName &lt;&lt; "@" &lt;&lt; destination &lt;&lt; "\n";
          } else
              cout &lt;&lt; "Error. Please enter either 'server' or 'client' for first argument in Connection().\n";
  
        string atString = "@";
        computerName = userName + atString + destination;
      }
      /*  Send function for class
      Accepts a string as an argument which contains the name of the file to be sent. And then it uses
      exec() system calls to use "scp" to send the file.
      Note: this assumes that passwordless ssh has been set up between the client and server machines.
      */
  
  
  
  
      /* ITS IN THIS FUNCTION THAT I GET THE ERROR. I SPLIT THE PROCESS WITH FORK, RUN 
         EXECL() AND THEN WAIT() ON THE CHILD PROCESS */
      int Send(string fileName)
      {
        pid_t pid;
         // char * parmList[] = {"scp", fileName, destination, NULL};
        int    status;
  
        if ((pid = fork()) &lt; 0) {     /* fork a child process           */
           printf("*** ERROR: forking child process failed\n");
           exit(1);
        }
        else if (pid == 0) {          /* for the child process:         */
           if (execl("scp", fileName.c_str(), computerName.c_str(), NULL) &lt; 0) {     /* execute the command  */
              printf("*** ERROR: exec failed\n");
              exit(1);
           }
        }
        else {                                  /* for the parent:      */
           while (wait(&amp;status) != pid)       /* wait for completion  */
              ;
        }
      }
  };
  
  
  int main()
  {
      Connection *con = new Connection("server");
      /* I'm just doing this to see if this works to create the string "testgoingnow". Who knows. */
      //string string = "test".append("going").append("now\n");
     string string1 = "test";
     string at = "@";
     string string2 = "going";
     string new_string = string1 + at + string2;
     cout &lt;&lt; new_string &lt;&lt; "\n";
  
     Send("test.txt");
  
      //cout &lt;&lt; string;
  
      return 0;
  }
  </code></pre>
  
  <p>And I get this compiler error:</p>
  
  <pre><code>connection.cpp: In member function ‘int Connection::Send(std::string)’:
  connection.cpp:64: error: no matching function for call to ‘wait::wait(int*)’
  /usr/include/bits/waitstatus.h:68: note: candidates are: wait::wait()
  /usr/include/bits/waitstatus.h:68: note:                 wait::wait(const wait&amp;)
  </code></pre>