Given a pointer p, can you determine whether p points to a valid object? If so, how? If not, why not?
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:2| Question number:2.23
All Answers
total answers (1)
No, you can't. 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.
need an explanation for this answer? contact us directly to get an explanation for this answerHowever, a *smart pointer* can be used to tell if it points to a valid object.