Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created December 24, 2011 19:29
Show Gist options
  • Save TheBuzzSaw/1518159 to your computer and use it in GitHub Desktop.
Save TheBuzzSaw/1518159 to your computer and use it in GitHub Desktop.
Hunt for Temporaries
#include <iostream>
using namespace std;
class LoudMouth
{
public:
LoudMouth(int inName) : mName(inName)
{
cout << "constructed " << mName << " at " << (void*)this << endl;
}
LoudMouth(const LoudMouth& inLoudMouth) : mName(inLoudMouth.mName)
{
cout << "copied " << mName << " to " << (void*)this << endl;
}
LoudMouth& operator=(const LoudMouth& inLoudMouth)
{
mName = inLoudMouth.mName;
cout << "assigned " << mName << " to " << (void*)this << endl;
return *this;
}
~LoudMouth()
{
cout << "destructed " << mName << " at " << (void*)this << endl;
}
private:
int mName;
};
LoudMouth doStuff()
{
LoudMouth a(7);
return a;
}
int main(int argc, char** argv)
{
LoudMouth a(1);
LoudMouth b = a;
LoudMouth c(2);
c = doStuff();
LoudMouth d(3);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment