How can I change an std::auto_ptr to a boost::shared_ptr? Here are my restrictions: 1. I am using an API class, lets call it only_auto that returns these pointers 2. I need to use the call in auto_only 3. My semantics involves sharing so I do need to use a shared_ptr) 4. In class only_auto operator = is private to prevent coping 5. Also a only_auto object must be made by a cloning call std::auto_ptr creat_only_auto();
我知道明确的共享_pdr( std: auto_ pdr & amp; r) 模板; 但我在这种情景下如何使用它?
超级简化代码示例 :
#include <iostream>
#include <memory>
#include <boost/shared_ptr.hpp>
using namespace std;
class only_auto
{
public:
static auto_ptr<only_auto> create_only_auto();
void func1();
void func2();
//and lots more functionality
private:
only_auto& operator = (const only_auto& src);
};
class sharing_is_good : public only_auto
{
static boost::shared_ptr<only_auto> create_only_auto()
{
return boost::shared_ptr (only_auto::create_only_auto()); //not the correct call but ...
}
};
int main ()
{
sharing_is_good x;
x.func1();
}