简体   繁体   中英

Get address of global operator delete?

Say I want to (for some reason) explicitely pass the global deleter to a unique_ptr as second argument. I guess the compiler must have some way of figuring out its address. How would I accomplish that? The following code doesn't compile:

#include <memory>

class some_class { };

int main()
{
    std::unique_ptr<some_class, decltype(delete)/*???*/> ptr { new some_class, delete/*???*/}
}

And what is the notation of getting operator addresses of class operators?

You cannot take the address of a delete expression because it is an expression, not a function. delete itself is just a language keyword. It exists only to form delete expressions.

If you want a deleter that deletes an object using a delete expression, use std::default_delete . Of course, that's the default deleter for std::unique_ptr , so there's no need to specify it explicitly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM