-
Book Overview & Buying
-
Table Of Contents
Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]
By :
Sometimes, programmers ask why they cannot simply have a generic pointer. That is, why must we always declare the type of data to which the pointer will eventually point, such as int *ptr;? C++ certainly does allow us to create pointers without associated types, but C++ then requires the programmer to keep track of things that would normally be done on their behalf. Nonetheless, we will see why void pointers are useful and what the programmer must undertake when using more generic void pointers in this section.
It is important to note that void pointers require careful handling, and their misuse can be extremely dangerous. We will, much later in the book, see a safer alternative to genericize types (including pointers) in Chapter 13, Working with Templates. Nonetheless, there are careful encapsulated techniques that use an underlying implementation of a void * for efficiency, paired with a safe wrapper of a template. We will see that...