RE: Initialization of a static member of a template class fails

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

 



Hi Valery,

I suspect your code is running into the dreaded Order Of Construction problem.  Which is only turn-of-the-screw less painful than the even more dreaded Order Of Destruction problem.

I replaced this part of your code...

static instance_list s_instances;

...with a class function to access a function-wrapped static instance_list variable...

static instance_list& GetInstanceList()
{
  static instance_list s_instances;
  return s_instances;
}

...and the crasher (which I also saw) went away.

Of course, you won't want a class static accessor function wrapping an instance variable in a header file, since that may cause even harder to diagnose problems.  Such as:  every translation unit* getting one-or-more copies of an inlined GetInstanceList.  Doh!

The solution to that latter problem is rather heinous (in my opinion), which involves explicit instantiation for all known instances of Enum<T> in a designated translation unit.  Ugh.  Maybe there is a more elegant solution.

HTH,
--Eljay

* Or compilation unit - whatever your terminological preference.


[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