This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pointers to object questions
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Andre Kirchner <supercroc1974 at yahoo dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 21 Jul 2004 11:29:53 -0500
- Subject: Re: pointers to object questions
- References: <20040721155758.46578.qmail@web50507.mail.yahoo.com>
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