Guest User

Untitled

a guest
Oct 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. int* x = nullptr;
  2. myclass* obj = nullptr;
  3.  
  4. template <class T>
  5. class ptr {
  6. T* p_;
  7. public:
  8. ptr(T* p) : p_(p) {}
  9.  
  10. template <class U>
  11. ptr(U* u) : p_(dynamic_cast<T*>(u)) { }
  12.  
  13. // Without this ptr<T> p(NULL) would be ambiguous
  14. ptr(int null) : p_(NULL) { assert(null == NULL); }
  15. };
  16.  
  17. ptr(std::nullptr_t) : p_(nullptr) { }
  18.  
  19. pointer-literal:
  20. nullptr
  21.  
  22. >>> None = 5
  23. File "<stdin>", line 1
  24. SyntaxError: assignment to None
  25. >>> type(None)
  26. <type 'NoneType'>
  27.  
  28. #include <iostream>
  29.  
  30. struct B {};
  31.  
  32. struct A
  33. {
  34. operator B*() {return 0;}
  35. operator bool() {return true;}
  36. };
  37.  
  38. int main()
  39. {
  40. A a;
  41. B* pb = 0;
  42. typedef void* null_ptr_t;
  43. null_ptr_t null = 0;
  44.  
  45. std::cout << "(a == pb): " << (a == pb) << std::endl;
  46. std::cout << "(a == 0): " << (a == 0) << std::endl; // no warning
  47. std::cout << "(a == NULL): " << (a == NULL) << std::endl; // warns sometimes
  48. std::cout << "(a == null): " << (a == null) << std::endl;
  49. }
  50.  
  51. (a == pb): 1
  52. (a == 0): 0
  53. (a == NULL): 0
  54. (a == null): 1
  55.  
  56. void f(int);
  57. void f(char*);
  58.  
  59. void g()
  60. {
  61. f(0); //calls f(int)
  62. }
  63.  
  64. void g()
  65. {
  66. f(nullptr); //calls f(char*)
  67. }
Add Comment
Please, Sign In to add comment