quote:Original post by d000hg
But this approach ties all the objects to a certain instance of the ''parent'' class - that doesn''t seem very object orientated. What if the object you store a link to is deleted, or replaced? Now you also have to put more extra safety code in. I just reckon a few globals is a lot easier.
It''s no more dangerous than a global that is allocated with malloc. And the ''particular instance'' could be allocated on the stack anyway. So there is no safety difference here. As for ''tying all objects'' to a certain instance, you have that anyway with the global. The benefit of the approach where you pass in the parameter is that one single extra line of code now lets you have 2 sets of objects, rather than adding another global and having to duplicate all the code that references it directly.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]