I am working in vs2019 and following code worked fine:
std::vector<Foo*> foos;
// fills vector
for (Foo* foo : foos) {
//do stuff
}
However, if i try to use unique_ptr
like this:
std::vector<std::unique_ptr<Foo>> foos;
// fills vector
for (std::unique_ptr<Foo> foo : foos) {
//do stuff
}
then both vs and compiler are complaining (if I understand correctly) about Foo
not having default delete. But std::unique_ptr<Foo>
is used without problems in other parts of the codebase.
Why is this happening and how to fix/circumvent this?