Is it good to send stack allocated object as a pointer parameter to some other function?
Share
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.
Yes, but the more common C++ idiom for this situation is to use a reference (and probably a const rreference) instead of a pointer. So instead of
you write:
This has the advantage that you don’t need to dereference the object in the caller:
and also gives a subliminal hint to the reader that you do not intend the function to take ownership of the object.