Why is there no std :: free overload for const void *?

I use the extern C function, which returns dynamically allocated const char*.

I want to use unique_ptr<const char, decltype(std::free)>to manage it.

But there is no overload std::free(const void*), so I get invalid conversion from 'const void*' to 'void*'and should use const_cast<char*>().

Is this just a defect in the standard library or is there something else behind?

+6
source share
1 answer

std::freeinherits from the standard C library. C has no overload, so the overload constcould not be inherited.

++ C , const ​​ free.

, , . - , , - , , .

, const_cast. .

+2

Source: https://habr.com/ru/post/1016204/


All Articles