How does the custom deleter of std::unique_ptr work?

后端 未结 4 489
青春惊慌失措
青春惊慌失措 2020-11-27 11:47

According to N3290, std::unique_ptr accepts a deleter argument in its constructor.

However, I can\'t get that to work with Visual C++ 10.0 or MinGW g++

4条回答
  •  庸人自扰
    2020-11-27 12:14

    This works for me in MSVC10

    int x = 5;
    auto del = [](int * p) { std::cout << "Deleting x, value is : " << *p; };
    std::unique_ptr px(&x, del);
    

    And on gcc 4.5, here

    I'll skip going to the standard, unless you don't think that example is doing exactly what you'd expect it to do.

提交回复
热议问题