C++ singleton using templates Is this a good Singleton implementation? Is there anything I should be aware of? If so, how can it be improved?

template &lt;class T&gt;
class Singleton
{
public:
    static T&amp; getInstance()
    {
        static T instance;
        return instance;
    }

protected:
    Singleton() {}
    ~Singleton() {}

private:
    Singleton(Singleton const&amp;);
    void operator=(Singleton const&amp;);
};


Usage example:

#include &lt;stdio.h&gt;

class A : public Singleton&lt;A&gt; {
public:
    A() {
        a = 100;
    }

    int get_a() { return a; }
    void set_a(int v) { a = v;  }
private:
    int a;
};

A&amp; s = A::getInstance();

void free1() {
    printf("%d\n", s.get_a());
}

void free2() {
    s.set_a(200);
}

void free3() {
    printf("--&gt; %d", s.get_a());
}

void main() {
    free1();
    free2();
    free3();
}


Let's consider an alternative to avoid the usage of Singletons, instead having:

class A : public Singleton&lt;A&gt;


let's say it becomes:

class A


and let's say we define a global variable:

A g_s = A();


and then this global variable will be accessed by other files using external, would that bring some sort of benefit?

external A g_s;
You cannot really say that it's a good or bad implementation. It depends, but this doesn't look ok to me: class A : public Singleton&lt;A&gt;.
You don't need to inherit from it to use it: Singleton&lt;A&gt;::instance()

If you want to to use it as you wrote: A&amp; s = A::getInstance(); then probably A's ctor/dtor shouldn't be public.