13
votes

Is there a C++/CLI RAII smart pointer class for containment of a native pointer in a managed type? Just wondering, before I go write my own clr_scoped_ptr value class template.

I'm aware of the Microsoft-provided:

The above two are similar to auto_ptr or unique_ptr.

But all these are for disposing managed ref class instances, not for freeing native objects.

1
Interesting. If you write your own clr_scoped_ptr, please post it as an answer. - ali_bahoo
@sad_man: Please see my code here: codereview.stackexchange.com/q/1695/2150 - Ben Voigt
I found this answer helpful as well: stackoverflow.com/a/12674472/929315 - Rotsiser Mho
@rotsiser: I see several serous errors in that one looking at it for just a minute. Nevermind that the intended behavior isn't even close to what this question asks for. - Ben Voigt
@BenVoigt: I found this question while looking for something to manage a native smart pointer (shared_ptr in my case) in a C++/CLI class. I'm sorry if the linked question wasn't helpful to you, but it helped me and I thought it may help others with similar needs who may come across this question. Are you aware of a more suitable solution for use with shared_ptr? - Rotsiser Mho

1 Answers

5
votes

This one looks fairly complete, but I'm not looking for silent transfer of ownership ala auto_ptr.


I've posted my version under a rather permissive license over at codereview.se