What are the uses of the type `std::nullptr_t`?

If more than one overload accepts a pointer type, an overload for std::nullptr_t is necessary to accept a nullptr argument. Without the std::nullptr_t overload, it would be ambiguous which pointer overload should be selected when passed nullptr. Example: void f(int *intp) { // Passed an int pointer } void f(char *charp) { // Passed a … Read more

Why is C++’s NULL typically an integer literal rather than a pointer like in C?

In C, a void* can be implicitly converted to any T*. As such, making NULL a void* is entirely appropriate. But that’s profoundly dangerous. So C++ did away with such conversions, requiring you to do most pointer casts manually. But that would create source-incompatibility with C; a valid C program that used NULL the way … Read more

Can a unique_ptr take a nullptr value?

It will work. From Paragraphs 20.7.1.2.3/8-9 of the C++11 Standard about the unique_ptr<> class template: unique_ptr& operator=(nullptr_t) noexcept; Effects: reset(). Postcondition: get() == nullptr This means that the definition of class template unique_ptr<> includes an overload of operator = that accepts a value of type nullptr_t (such as nullptr) as its right hand side; the … Read more

Is it safe to #define NULL nullptr?

I have seen below macro in topmost header file: You shouldn’t have seen that, the standard library defines it in <cstddef> (and <stddef.h>). And, IIRC, according to the standard, redefining names defined by standard header files results in undefined behaviour. So from a purely standardese viewpoint, you shouldn’t do that. I’ve seen people do the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)