I am creating a custom object and overriding the + operator. I am return a new object of the same type. Is it bad practise to allocate memory inside this method? because I then I will need to delete the memory out of scope.
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, without further information, it is bad.
Usually you do:
That said, you could return a unique_ptr if you really had to allocate dynamically.