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

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

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

<code>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();
</code>

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

<code>A<int> a;
//no output
</code>

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

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

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

Ответы на вопрос(2)

Ваш ответ на вопрос