Created
February 22, 2012 05:59
-
-
Save draggor/1881910 to your computer and use it in GitHub Desktop.
thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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