Re: Who's in charge of AddRef'ing?
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Tue, 27 Jan 2009 18:13:12 -0500
alamaison <newsgroups@xxxxxxxxxxx> wrote:
Roman Ryl... wrote:
CComPtr<IChild> m_pChild;
STDMETHOD(get_child)(IChild** ppChild)
{
if(!ppChild)
return E_POINTER;
*ppChild = CComPtr<IChild>(m_pChild).Detach(); // leave AddRef on
stack, in the out'ted variable
I'm not sure this is a good idea for a 'get' method. Detach()
destroys the existing reference (m_pChild) which CopyTo() does not.
Note that in the example, Detach is called on a temporary CComPtr object
holding a copy of m_pChild, not on m_pChild itself. When this copy was
constructed, AddRef was called. The net effect is equivalent to CopyTo,
though more verbose.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: Who's in charge of AddRef'ing?
- From: alamaison
- Re: Who's in charge of AddRef'ing?
- References:
- Who's in charge of AddRef'ing?
- From: Igor R.
- Re: Who's in charge of AddRef'ing?
- From: Roman Ryl...
- Re: Who's in charge of AddRef'ing?
- From: alamaison
- Who's in charge of AddRef'ing?
- Prev by Date: Re: Who's in charge of AddRef'ing?
- Next by Date: Re: Who's in charge of AddRef'ing?
- Previous by thread: Re: Who's in charge of AddRef'ing?
- Next by thread: Re: Who's in charge of AddRef'ing?
- Index(es):
Relevant Pages
|