Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
C++ keyword to dynamically allocate memory and returning a pointer to this memory location. If the allocation of memory fails, std::bad_alloc is thrown and a pointer to null is returned.
When the pointer is no longer needed, delete must be called.
Prefer the use of std::auto_ptr (or other smart pointers) over the use of plain pointers [1][2].
int main() |
Suppose you have a base class called Animal and a derived class called Monkey. Then you can store a Monkey as an Animal in the following way.
int main() |
Prefer the use of std::auto_ptr (or other smart pointers) over the use of plain pointers [1-3].
#include <memory> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.