/*Orion Lawlor's Simple C++ Examples, olawlor@acm.org
Shows when the destructor gets called on a compiler-generated
return value.
*/
#include <iostream>
void at(const char *where1,const char *where2) {std::cout<<where1<<where2<<"\n";}

class foo {
	const char *tag;
public:
	foo(const char *Ntag):tag(Ntag) {at("foo constructor: ",tag);}
	~foo() {at("foo destructor: ",tag);}
};

foo fn_returning_foo(void) {
	return foo("return");
}
void bar(void) {
	const foo &f=fn_returning_foo();
	std::cout<<"Inside bar\n";
}

int main()
{
	bar();
	std::cout<<"After bar\n";
	
	return 0;
}
/*<@>
<@> ******** Program output: ********
<@> foo constructor: return
<@> Inside bar
<@> foo destructor: return
<@> After bar
<@> */
