Alright first lets look at a sample piece of code before I ask my question.
Code:
class foo
{
public:
foo() { x = 0; }
void put( int i ) { x = i; }
int get( void ) { return x; }
private:
int x;
};
int main()
{
foo bar;
bar.put( 1 );
cout << bar.get() << endl;
bar = foo();
cout << bar.get() << endl;
}
Ok my question is about the line "bar = foo();" Now I know what happens to bar, when i call bar.get() I output a 0. But what I'm wondering is, what exactly is that line of code doing there? Is it making bar call it's constructor again, or is it creating a temporary object of foo and copying that to bar then freeing itself, or not freeing itself staying in memory wasting space? Or is it doing something not in that list?
Thanks.