fork download
  1. #include <iostream>
  2. #include <list>
  3.  
  4. namespace NS1
  5. {
  6. template <class T>
  7. class Base
  8. {
  9. protected:
  10. Base()
  11. {
  12. instances.push_back(static_cast<T*>(this));
  13. }
  14. private:
  15. static std::list<T*> instances;
  16. };
  17.  
  18. namespace NS1_1
  19. {
  20. template <class U>
  21. class Intermediary : public Base<U>
  22. {
  23. protected:
  24. Intermediary()
  25. :Base<U>()
  26. {
  27. }
  28. };
  29.  
  30. class Derived : public Intermediary<Derived>
  31. {
  32. public:
  33. Derived()
  34. :Intermediary<Derived>()
  35. {
  36. }
  37. };
  38. }
  39. }
  40.  
  41. template <> std::list<NS1::NS1_1::Derived*> NS1::Base<NS1::NS1_1::Derived>::instances;
  42.  
  43. int main()
  44. {
  45. NS1::NS1_1::Derived d;
  46. return 0;
  47. }
  48.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/peCbZi/cc4wDaLr.o: In function `main':
prog.cpp:(.text+0x5c): undefined reference to `NS1::Base<NS1::NS1_1::Derived>::instances'
collect2: ld returned 1 exit status
stdout
Standard output is empty