在调用std :: unique之后,如何删除向量中的指针?
例如:
struct Foo
{
Foo(int bar) : mBar(bar) {}
~Foo() { std::cout << "~dtor\n"; }
int mBar;
};
bool SortFunc(Foo * right, Foo * left) { return right->mBar < left->mBar; }
// Should I 'delete left;' in case of equality?
bool CompareFunc(Foo * right, Foo * left)
{
return right->mBar == left->mBar;
}
// NOTE: In my code, vector is initialized in another class which I cannot modify.
void InitializeList(std::vector<Foo *> & fooList)
{
Foo * firstFoo …Run Code Online (Sandbox Code Playgroud)