Reputation: 113
i don't understand fully this problem. This is my function and i need return class with unique_ptr how can i this?
my list:
std::list<std::unique_ptr<Maths> > l_MathsList;
my function
Maths* Maths2::FindMathsID(int iID)
{
auto mpClass= std::unique_ptr<Maths>();
for (auto&& it : l_MathsList)
{
if (iter->IsMy(iID)) {
mpClass = std::move(it);
}
break;
}
}
return mpClass; // compiler error
Upvotes: 1
Views: 87
Reputation: 36513
You probably just want to return a non-owning pointer to the collection element right?
In that case just use .get()
:
Maths* Maths2::FindMathsID(int iID)
{
for (auto& it : l_MathsList)
{
if (it->IsMy(iID))
return it.get();
}
return nullptr;
}
Upvotes: 1