I'm aware of Singleton Pattern, my original code is a very simplistic implementation to show my problem. The point here is not about the quality of the pattern but the number of instances when using these flags: -fvisibility=hidden -fvisibility-inlines-hidden and __attribute__ ((visibility("default"))) Of course if I don't use these flags I only have one instance. On Friday 03 June 2005 15:52, Martin York wrote: > There are many ways to implement the Singleton Pattern. Each has their > own positives and negatives. I would advice looking at "Scott Meyers" > book "More Effective C++" > http://www.amazon.co.uk/exec/obidos/ASIN/020163371X/ref=pd_bxgy_text_2_c > p/026-5023597-8506032 > > > Personally I prefer being as simple as possible (Like your original > code). > > > > The only problem with your original code is that > > singleton* singleton::instance() > > is defined in the header file. Therefore the implementation of instance > is not in the resulting shared library. > > If you move the definition into the file singleton.cc then I believe > (though not tested) that your problem will be resolved. Can I move templated code to the implementation file? I thought that templated code should be written in the declaration file. > > As a secondary question/comment. Why return a pointer. To me this > implies it can fail and return a NULL (and thus needs to be checked). I > (personally) would return a reference. [...] -- Filipe Sousa
Attachment:
pgpeGzBQAYi3T.pgp
Description: PGP signature