How do you initialize a static template container?

I am trying to figure out the correct way to initialize a static container variable whose template value is a private inner class. Here is an example of a toy

#include <vector> using namespace std; template <class myType> class Foo { private: class Bar { int x; }; static vector<Bar*> bars; }; template <class myType> vector<Bar*> Foo<myType>::bars; // error C2065: 'Bar' : undeclared identifier 

I also tried

 ... template <class myType> vector<Foo<myType>::Bar*> Foo<myType>::bars; // error C2059: syntax error : '>' 

It works if class Bar declared outside of class Foo , but from a design point of view it is an ugly solution. Any suggestions?

FYI, everything is declared in the .h file.

+7
c ++ static class templates nested
source share
2 answers

Try the following:

 template <class myType> vector<typename Foo<myType>::Bar*> Foo<myType>::bars; 
+10
source share

vector<Foo::Bar*> Foo<myType>::bars; ... pay attention to Foo::

-one
source share

All Articles