Say I have the following:
Foo* foo = new Foo(bar);
//later on
*foo = Foo(anotherBar);
Since foo was allocated on the heap does this cause problems or will the memory from the temporary Foo be copied into the address of foo on the heap?
Thanks
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.
*foo = Foo(anotherBar);is no different than a regular assignment to an object ofFootype.*fooreturns an lvalue of type Foo, and you are assigning to it.Short answer: it won’t cause problems, the temporary will be copied into the heap
Fooobject pointed byfoo.