Re: pointers to object questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux