first:
LPCTSTR asdfsdf = (LPCTSTR)(_bstr_t)v;
printf("%s\n", asdfsdf);
second:
printf("%s\n", (LPCTSTR)(_bstr_t)v);
they are the same, but the first condition causes unreadable code
why?
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.
The
_bstr_tclass encapsulates a BSTR inside a C++ class. In your first instance:you are creating a
_bstr_tobject, extracting theLPCTSTRout of it, but then the temporary_bstr_tobject gets destructed. Whateverasdfsdfpointed to is now deallocated and can no longer be used.In your second example
the temporary
_bstr_tobject is not destructed until after theprintf()is called, so there is no problem using theLPCTSTRvalue.