Singleton instantiated more than once with -fvisibility=hidden
Filipe Sousa
filipe@ipb.pt
Fri Jun 3 13:09:00 GMT 2005
On Friday 03 June 2005 13:46, Mws wrote:
> hi,
>
> in my understanding a singleton is used to have a class
> instanciated only for one time.
>
> normally this is done by
>
> having the "wanted-to-be-singleton-class" derived/inherited from
> a singleton class or template.
> never ever from the outside ctors are called, but there should be
> a getInstance() method that checks for _m_instance == NULL
> if it is matching creating a new instance with new, otherwise returning the
> _m_instance pointer.
A templated version
template<class T>
class singleton {
public:
static T* instance() {
if (!m_instance)
m_instance = new T;
return m_instance;
}
private:
static __attribute__ ((visibility("default"))) T* m_instance;
};
class __attribute__ ((visibility("default"))) my_singleton : public
singleton<my_singleton> {
public:
my_singleton() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};
> if you want to, i can provide you with a complete singleton template.
Yes, please
> regards
> mws
--
Filipe Sousa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20050603/99605d1d/attachment.sig>
More information about the Gcc-help
mailing list