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
Maths*and then you've elected to return astd::unique_ptr. The compile error likely tells you as much. Either change the return type or quit making a smart pointer.cannot convert 'std::unique_ptr<MathFuncs::Maths>' to 'MathFuncs::MathFuncs*' in returnunique_ptr, then the return type should bestd::unique_ptr<Maths>. But note that, once you've called this function once, some prefix of the listl_MathsList(which I presume is an instance variable) will be left empty and therefore inaccessible.