Re: Singleton instantiated more than once with -fvisibility=hidden

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: pgpLpW9aMUIGh.pgp
Description: PGP signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux