C++ Is it possible to determine whether a pointer points to a valid object?

No, you can’t. Why? Because it would be expensive to maintain meta data about what constitutes a valid pointer and what doesn’t, and in C++ you don’t pay for what you don’t want.

And you don’t want to check whether a pointer is valid, because you know where a pointer comes from, either because it’s a private part of your code that you control, or because you specified it in your external-facing contracts.

Leave a Comment