In the below example, we instantiate a thermo object and we pass it as an argument to set_thermo. Now the fact that I passed that object by reference, does that mean when this function exits, since thermo was declared in this scope, that the reference will be deleted? If I pass thermo by value rather than reference, when this function exits, will thermo still exist as an attribute of report?
WHat if I use this instead:
With this definition:
That definition would create a copy... so you'd be safe. This is what I'd recommend.
Your Report class would then have its own THermo object and would not need to refer to an outside object. So when the local 'thermo' object in readReports goes out of scope and dies... you have no problem because Report wouldn't be using it any more.
Although if you change the function to pass by value... then this: report.set_thermo(&thermo);
won't work because you're passing it a pointer. You'd have to remove the & in this case.