-
Notifications
You must be signed in to change notification settings - Fork 0
Null_ptr
DryPerspective edited this page Oct 9, 2023
·
1 revision
A null_ptr a stand-in for C++11's nullptr. As nullptr is a language feature and this library cannot add those, dp::null_ptr is an instance of a class type dp::null_ptr_t which is implicitly convertible to any pointer type, but not to any other types. dp::null_ptr can be used in any place where NULL would be expected, but will not be converted to a non-pointer type.
dp::null_ptr should be switched out for nullptr upon any update to C++11 or later.
| null_ptr | A null pointer which cannot be converted to an arithmetic type |
#include <iostream>
#include "cpp98/null_ptr.h"
void f(int){
Print("Integer overload");
}
void f(int*){
Print("Pointer overload");
}
int main(){
f(NULL); //Prints "Integer overload"
f(dp::null_ptr); //Prints "Pointer overload"
}