This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pointers to object questions
- From: Andre Kirchner <supercroc1974 at yahoo dot com>
- To: Eljay Love-Jensen <eljay at adobe dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 21 Jul 2004 10:22:12 -0700 (PDT)
- Subject: Re: pointers to object questions
Hi Eljay,
Thanks for the help, and sorry for posting an
off-topic question.
The problem that I was having was related to your 3rd
advice. The live span of theData was too short, and I
fixed it by adding "Data * theData;" to the Data.h
file, and then making the Sender constructor like
Sender::Sender( Connector * newConnector )
{
theConnector = newConnector;
theData = new Data( newConnector );
}
Also, thanks for the Smart Pointers webpage. I'm going
to study it because I still have a lot to learn :-)
Andre
--- Eljay Love-Jensen <eljay@adobe.com> wrote:
> 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
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail