Re: unfamiliar idiom
firstname.lastname@example.org () wrote (abridged):
Is this nonsense or does it makes sense? Any pros and cons?
I think it could be applicable when this kind off runtime
information about all living objects of some class is needed.
I have used a similar idiom in real programs. It is a scary thing to do.
As with any singleton, you have a potential covert channel of
communication between different parts of the program. Widgets created by
different modules for different reasons will end up in the same
collection. You have to be careful about losing modularity. I would see
it as a kind of metaprogramming, so you also have to be careful about
mixing levels of abstraction.
In your particular implementation, you need to be aware that if some
class inherits from Widget, its instances will be added to the collection
before they are fully constructed. From the collection they can be
accessed from anywhere, still in their incomplete state. This may not be
a problem in any particular use, but it is an example of the kind of
scariness I mentioned. It gives me the willies, anyway.
-- Dave Harris, Nottingham, UK.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]