开发者

How do you initialize a static templated container?

开发者 https://www.devze.com 2023-01-18 16:55 出处:网络
I\'m trying to figure out the correct way of initializing a static container variable whose template value is a private inner class. Here\'s a toy example

I'm trying to figure out the correct way of initializing a static container variable whose template value is a private inner class. Here's a toy example

#include <vector>

using namespace std;

template <class myType>
class Foo {
private:
    class Bar {
        int x;
    };

    sta开发者_Python百科tic vector<Bar*> bars;
};

template <class myType>
vector<Bar*> Foo<myType>::bars; // error C2065: 'Bar' : undeclared identifier

I've also tried

...

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

It works if class Bar is declared outside of class Foo but from a design standpoint this is an ugly solution. Any suggestions?

FYI, everything is declared in a .h file.


Try this:

template <class myType>
vector<typename Foo<myType>::Bar*> Foo<myType>::bars;


vector<Foo::Bar*> Foo<myType>::bars; ... note the Foo::

0

精彩评论

暂无评论...
验证码 换一张
取 消