![]() |
Re: VS2012 VC++ std::unique_ptr broken!
On 22.11.2012 00:39, Leigh Johnston wrote:
> Hi, > > From > https://connect.microsoft.com/Visual...her-than-after > : > > "ISO C++11 mandates that std::unique_ptr<T>::reset() deletes the owned > object *after* resetting the pointer to the owned object rather than > before as VC10 and VC11 are currently doing. > > ... > This can cause a problem if the destructor of the owned object calls > back to code which attempts to call reset() a second time on the same > unique_ptr object resulting in double delete; workaround is to take a > local copy of the unique_ptr object rather than use reset()." > Not sure I get the workaround. Can you post a code sample? cheers, Martin |
Re: VS2012 VC++ std::unique_ptr broken!
On 22.11.2012 22:07, Leigh Johnston wrote:
> On 22/11/2012 21:06, Leigh Johnston wrote: >> class wibble >> { >> typedef std::unique_ptr<foo> foo_pointer; >> foo_pointer m_MyFoo; >> ... >> ... > Oops; that should have been: > > class wibble > { > typedef std::unique_ptr<foo> foo_pointer; > foo_pointer m_MyFoo; > ... > ... > void f() > { > ... > ... > { foo_pointer destroyingCopy(m_MyFoo); // instead of > m_MyFoo.reset(); } > ... > ... > } > ... > ... > }; > I'm confused. I thought you cannot copy a unique_ptr -- should that be foo_pointer destroyingCopy(std::move(m_MyFoo)); instead? cheers, Martin |
| All times are GMT. The time now is 01:16 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.