Я новичок в unique_ptr. Все шло хорошо, пока я не наткнулся на функцию, возвращающую новый unique_ptr. Компилятор, кажется, жалуется на более чем один объект, потенциально владеющий unique_ptr. Я не уверен, как удовлетворить жалобу компиляторов. Любая помощь приветствуется.
void Bar::Boo()
{
...
// m_Goals is of type std::unique_ptr<Goals>
auto x = m_Goals->Foo(); // error: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'
//auto x = std::move( m_Goals->Foo() ); // same error
...
}
const std::unique_ptr<Goals> Goals::Foo()
{
std::unique_ptr<Goals> newGoals( new Goals() );
...
return newGoals;
// also tried "return std::move( newGoals )" based on http://stackoverflow.com/questions/4316727/returning-unique-ptr-from-functions
} // this function compiles