Last active
December 30, 2015 07:39
-
-
Save coldcue/7797783 to your computer and use it in GitHub Desktop.
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
//Java pass-by-value | |
public void foo(Dog d) { | |
d.getName().equals("Max"); // true | |
d = new Dog("Fifi"); | |
d.getName().equals("Fifi"); // true | |
} | |
Dog aDog = new Dog("Max"); | |
foo(aDog); | |
aDog.getName().equals("Max"); // true | |
//C++ corresponding (pass d reference by value) | |
public void foo(Dog &d) { | |
//d still points to a *Dog pointer | |
d->getName() == "Max"; //true | |
d = new Dog("Fifi"); | |
d->getname() == "Fifi"; //true | |
} | |
Dog *aDog = new Dog("Max"); | |
foo(&aDog); | |
aDog->getName() == "Max"; //true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment