Skip to content

Instantly share code, notes, and snippets.

@draggor
Created February 22, 2012 05:59
Show Gist options
  • Save draggor/1881910 to your computer and use it in GitHub Desktop.
Save draggor/1881910 to your computer and use it in GitHub Desktop.
thing
#include <iostream>
using namespace std;
class Thing{
public:
int* val;
Thing() {}
Thing(int i) { val = new int; *val = i; }
~Thing() { delete val; }
Thing(Thing& t) { val = new int; val = t.val; cout << "Copied " << *val << endl; }
};
void doSomething(Thing t) {}
void doSomethingElse(Thing& t) {}
int main()
{
Thing* t1 = new Thing(5);
Thing t2(10);
doSomething(t2);
doSomething(*t1);
doSomethingElse(t2);
doSomethingElse(*t1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment