Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is temporary allocation?

In C++, what is temporary allocation and when is it used? Does such a thing even exist? It was mentioned in the TA's course notes, but I couldn't find any info about it...

like image 387
hizki Avatar asked Dec 05 '25 10:12

hizki


1 Answers

When people say "temporaries" they often refer to rvalues. That is objects created and not bound to a variable name, thus not living outside the current statement. IE:

int foo()
{
     Do( Object() );
}

The created Object() is an rvalue which you may hear referred to as a temporary.

like image 113
Doug T. Avatar answered Dec 11 '25 08:12

Doug T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!