Answer to C++ Programming Puzzle
Wednesday July 9, 2008
The answer is there are at least four. The first one is quite subtle:
- You can overwrite the private variable like this!
*Earth.GetPlanetName() = 0;That's not exactly private!
- It doesn't trap a null name.
- It leaks in two places! When the object goes out of scope, nothing frees up PlanetName. There's no destructor.
- When a new name is assigned, the old one is lost but the memory is not freed up. Another leak!


This is really nice catch…
I was a C++ programmer.. now i really lost all of my touch with beautiful c++… this might be a good call for me to come home… !!
I agreed with you