Converting pointers

You can either have typed pointers, or the void* pointer. Typed pointers will access the memory as if it is the specified type (this has interesting consequences when you have inheritance with classes, but that will be left for Chapter 6, Classes and Chapter 7Introduction to Object-Oriented Programming). Thus, if you cast a pointer to a different type and dereference it, the memory will be treated as containing the cast type. It rarely makes sense to do this. The void* pointer cannot be dereferenced, so you can never access data through a void* pointer, to access the data you have to cast the pointer. The whole reason for the void* pointer type is that it can point to anything. In general, void* pointers should only ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.