Why I am getting linking error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Singleton
{
private:
 static Singleton* _SInstance;
public:
    Singleton(){}
    static void _GetInstance()
    {
       _SInstance = new Singleton();
    }
};
//Singleton * Singleton::_SInstance=NULL;

int main()
{
   Singleton::_GetInstance();
   return 0;
}


In the above program when I compile I am getting linking
Error: undefined reference to 'Singleton::_SInstance'
But when I Initializing NULL to the _SInstance in global scope.
Its works fine.

So my question is why the linking error? When it is not Initialized
@ne555: Thanks for replying. I got the answer now.

I modified my Singleton class to unserstand the Static variable behaviour and posted here.
put the constructor under private. Otherwise there is no point in making it singleton.
Topic archived. No new replies allowed.