开发者

shared_ptr - ccomptr swap

I got a simple question here

Let's suppose we have a codebase that employs usage of shared_ptr/enable_shared_from_this.

And we have been asked to convert -a portion of- the codebase into a COM server where we are supposed to use CComPtr instead, while it is not a mandatory requirement...

now here开发者_运维知识库 is the question; Is there any functionality within the atl/com+ that mimics enable_shared_from_this?


There is no need for enable_shared_from_this when using CComPtr because CComPtr does not maintain a reference count. Instead, the object it points to maintains the reference count. All CComPtr does is call member functions on the object that increment or decrement the reference count. There is no problem with doing the following:

void Func(IUnknown* someObj)
{
    CComPtr ptrA = someObj;
    CComPtr ptrB = someObj;
}


There are lots of rules for COM objects, it's not as easy as declaring a smart pointer. I'd suggest studying up on the subject, it's not something that can be condensed into a short answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜