Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Dec 21, 1998

The Lifetime of a Bound Temporary Object

You can safely bind a reference to a temporary object. The temporary object to which you bind the reference persists for the lifetime of the reference.
 
class C {
  int j;
public:
  C(int i) : j(i) {}
};

void main() 
{
  const C& cr = C(5);//bind a reference to a temp; temp's destruction deferred to the end of the program
  C c2 = cr; //use the bound reference safely
}//temporary destroyed here along with its bound reference 
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date