next up previous
Next: L.1.2 Large Messages Up: L.1.1 Passing Pointers Previous: L.1.1 Passing Pointers

Example program:

//#include "header.h"

class Remote {
public:
  Remote(char * fileName)
    {      
      char temp[100];
      strcpy(temp,fileName);
      strcat(temp,".errors");
      errorFile.open(temp);
      errorFile << "Opened" << endl;

      outFile.open(fileName);
      errorFile << "OutFile opened" << endl;
    }
  
  int do_work()
    {
      outFile << "Hello from Remote " << endl;

      errorFile << "Do Work called for object " << endl;

      return 1;
    }


private:
  ofstream  outFile;
  ofstream  errorFile;

};

class Local {
public:
  Local()
    {
      theRemote = new Remote("temp");
    }

  int do_work()
    {
      theRemote->do_work();
      return 1;
    }
private:
  Remote *theRemote;
};


main()
{
  Local *p = new Local;
  
  p -> do_work();
  p -> do_work();
  p -> do_work();
  p -> do_work();
  p -> do_work();
  p -> do_work();
  
}



Jonathan Poole
Tue Jun 27 16:38:45 BST 1995