Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A pointer is a type that holds an address.
When a pointer is uninitialized, it should point to NULL. You initialize a pointer using new, which reserves free space for the dynamically allocated instance and returns the address to it.
C++ does not free this memory on its own. Therefore, you have to call delete to do so.
Reading/writing from/to an uninitialized pointer results in an access violation.
Prefer using a smart pointer over a plain pointer [1-3], e.g. use an std::auto_ptr or boost::shared_ptr. Use 0 rather than NULL [4].
Avoid non-trivial pointer arithmetic [5].
struct MyClass { /* some class definition */ }; |
#include <memory> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.