Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Pointers in C++

Pointers

  1. No pointer, no polymorphism.

  2. C/C++ is notorious for raw pointers. While pointers can boost up the speed of programs, it invites a trillion chances for making mistakes. You should avoid using raw pointers, instead, consider using unique_ptr, shared_ptr and weak_ptr. They are almost as efficient as raw pointers but much safer to use.

  3. If p is a dynamically allocated array, you have to use delete[] p to delete it when it is no longer required.

  4. auto_ptr objects cannot be stored in STL containers, because they are not copy-construable or assignable.

Comments