Possible Duplicate:
Why does the use of ‘new’ cause memory leaks?
What is the difference between (if there is one):
Player player=*(new Player());
and:
Player &player=*(new Player());
Both (seem to) behave the same way, but I surely miss something?!?
The difference is that the first makes a copy, whereas the second creates a reference to the object pointed to by the pointer returned by
new Player().copy-initializes
playerusing the copy-constructor.just creates an alias for
*(new Player()), which is valid becausenew Player()isn’t a temporary.Player& player = Player()would be illegal because of that.They’re the same in that they both suck.