This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pointers to object questions


Hi Andre,

Your question is off-topic for this forum, as it is not a GCC related question. Rather, it is a C++ related question.

Given that, here's my advice.

#1...
Is NULL allowed to be passed into Sender::Sender(Connector* newConnector)?

If not, then I recommend you change it to Sender::Sender(Connector& newConnector). That also means changing Sender's member variable from "Connector* theConnector" to "Connector& theConnector", and doing the initialization in the Sender::Sender's initialization list.

Note: if "Connector" is the root of a hierarchy of different kinds of connectors, you may run into some issues for non-const reference passing. In my opinion, it's worth taking the time to resolve those issues.

#2...
Who owns theConnector?

Is ownership being passed in? No, not really. But if it were, I'd say you should pass in the Connector object via auto_ptr<Connector>, which indicates a transfer of ownership.

Is ownership being shared (or distributed)? Yes, sort of. I recommend looking at BOOST Smart Pointers: <http://www.boost.org/libs/smart_ptr/smart_ptr.htm>.

#3...
The answer to "What could be wrong" ... you should provide a compilable small example that demonstrates the problem. My own toy example doesn't exhibit the problem. NOTE: the lifespan of Data theData object expires quite quickly: at the end of the Sender constructor.


HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]