Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-06-21 15:20:50


From: H <h.v.niekerk_at_[hidden]>
> Martin Bonner wrote:
> > From: H. van Niekerk [mailto:h.v.niekerk_at_[hidden]]
> >>
> > Incidentally, I don't think the presence of three .cpp files is directly
> > relevent. I suspect that the relevent factor is that you have three
> > *functions*, and your problem is passing the data between them.
> >
> Thank you for your response. I hope the code below explains more:
>
> Master.cpp
> {
> Client c;
> c.readFromSatellite(input);
> cout << "input = " << input << endl;
> }
>
> Client.cpp
> {
> Satellite s;
>
> readFromSatellite(input)
> {
> s.readFromInterface(input);
> return input;
> }
> }
>
> Satellite.cpp
> {
> readFromInterface(input)
> {
> // Here the actual reading is done
> fti->writeAndReadAllData(output, input);
> return input;
> }
> }

As Martin said, the separate files aren't relevant. Also, the
usage and declarations of your functions aren't consistent.

Let's see if I can recast your problem to something a little
simpler to discuss:

   void function2(some_type data) // stores stuff in caller's object
   {
      read_something_from_somewhere(data);
   }

   void function1(some_type data) // stores stuff in caller's object
   {
      function2(data);
   }

   void function3(some_type data)
   {
      // do something useful with data
   }

   int main()
   {
      some_type data; // some pointer type
      function1(data); // stores stuff in data
      function3(data);
   }

Is that a good approximation of what you want?

If so, some_type should be boost::shared_ptr<something> and the
rest should just work. Of course, you can avoid using
boost::shared_ptr if function1() and function2() take non-const
references to some_type:

   void function2(some_type & data) // stores stuff in caller's object
   {
      read_something_from_somewhere(data);
   }

   void function1(some_type & data) // stores stuff in caller's object
   {
      function2(data);
   }

   void function3(some_type const & data)
   {
      // do something useful with data
   }

   int main()
   {
      some_type data; // not a pointer type
      function1(data); // stores stuff in data
      function3(data);
   }

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk