-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Refactoring with C++
By :

In C++, pointers are a fundamental part of the language, allowing direct memory access and manipulation. However, the flexibility that pointers offer comes with certain risks and challenges. Here, we’ll explore how modern C++ techniques can enhance pointer safety.
Raw pointers, while powerful, can be a double-edged sword. They provide no information about the ownership of the object they point to, and they can easily become “dangling” pointers, pointing to memory that has been deallocated. Dereferencing a null or dangling pointer leads to undefined behavior, which can result in hard-to-diagnose bugs.
The not_null
wrapper provided by the Guidelines Support Library (GSL) aims to overcome the challenges associated with raw pointers. By using not_null
, you can clearly signal that a pointer should never be null:
#include...