All,
As the simple sample program below demonstrates, function arguments are
destroyed after the return value of the function has been evaluated. As
opposed to local function variables, which are destroyed before the
function returns.
Is this correct? (To the best of my knowledge it is)
Where in the standard is this described?
Thanks,
Andre
--- Example ---
#include <iostream>
using namespace std;
class test
{
public:
test( string s = "")
: s_(s)
{
cout << "test::test()\t" << s_ << endl;
}
test( const test &org)
{
cout << "test::test(copy)" << endl;
s_ = "copy of " + org.s_ ;
}
~test()
{
cout << "test::~test()\t" << s_ << endl;
}
const string & getStr() const
{
return s_;
};
private:
string s_;
};
const test & f( test arg )
{
test l("local");
return arg;
}
int main()
{
test c("main");
cout << "\n\t\tf() = [" << f( c ).getStr() << "]\n" << endl;
}