Given:
MY_CLASS* ptr = MY_CLASS::GetSomeInstance();
What is the correct way to output ptr to std::cerr, so I can log its value? Note I don’t want to write the class, just the address.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
operator<<is overloaded to take aconst void*, so you can simply insert the pointer into the stream:The exception is that if the pointer is a
const char*, it will be interpreted as a pointer to a C string. To print the pointer, you need to cast it explicitly to aconst void*: