Почему статические поля шаблона не инициализируются, если не используются? [Дубликат]

Possible Duplicate:
(static initialization/template instantiation) problems with factory pattern
trying to force static object initialization

EDIT: There is a duplicate of this but I'll leave this up as I personally had trouble finding it. In addition here's the answer that helped me:

https://stackoverflow.com/a/2852234/673730

Предположим, следующий класс:

template<class X>
struct A
{
   static bool x;
   static bool foo()
   {
      cout << "here";
      return true;
   }
};

template<class X>
bool A<X>::x = A<X>::foo();

Я бы предположил, что, когда я специализируюсьAстатическое полеx&nbsp;будет инициализирован. Тем не менее, следующее:

A<int> a;
//no output

не приводит к вызовуfoo, Если я пытаюсь получить доступ к члену, поведение будет таким, как ожидалось:

A<int> a;
bool b = a.x;
//output: here

РЕДАКТИРОВАТЬ:How can I make sure A::x is initialized without accessing it?