
Rob Stewart wrote:
From: H <h.v.niekerk@hccnet.nl>
Martin Bonner wrote:
From: H. van Niekerk [mailto:h.v.niekerk@hccnet.nl]
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); }
After reviewing the groups on this news-server, I think I'm posting to the wrong group. If you agree with that view, please let me know. I'll follow up to the user group then. H.