小编Mur*_*der的帖子

使用std :: unique时如何防止悬空指针?

在调用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)

c++ algorithm containers pointers unique

2
推荐指数
1
解决办法
342
查看次数

标签 统计

algorithm ×1

c++ ×1

containers ×1

pointers ×1

unique ×1