Problem with template

This is a discussion on Problem with template within the C++ Programming forums, part of the General Programming Boards category; I want to write an auto_ptr implementation for Core Foundation objects, but I'm having a little problem with making a ...

The problem is that if you accept an argument by non-const reference, you can't pass a temporary to it.

I guess, here you could call your other constructor:

Code:

CF_auto_ptr<CFBundleRef> main_bundle(CFBundleGetMainBundle());

In any case, mimicking the semantics of std::auto_ptr (ownership transfer) might not be worth it (it is practically a deprecated class).

Instead, if you want, you should be easily able to share resources with boost::shared_ptr (or std::tr1::shared_ptr), which allow to use a custom deleter. Or you might just make you auto_ptr non-copyable (like std::tr1::unique_ptr or boost::scoped_ptr).