最近迷上了STL库。。一边使用一边trace它的源代码,可是发现了一个问题是关于allocator中的rebind,其定义如下:template
class allocator
: public _Allocator_base<_Ty>
{
//....other code...
template
struct rebind
{ // convert an allocator<_Ty> to an allocator <_Other>
typedef allocator<_Other> other;
};
//....other code...
};
而在使用的时候的写法如下:
typename _Alloc::template rebind<_Node>::other _Alnod; typename是为了使用struct rebind存在,那么中间那个template呢?为什么要加那个template?从bnf分析的角度来看,似乎也无法解释它的存在我用的是VS.net2003,而我把这个问题交给我的数据结构老师后,他说他也无法说明这个问题,不过他说sgi等其他的STL中没有这样的用法,但VC++.Net中到处都是
请各路高手赐教。。
class allocator
: public _Allocator_base<_Ty>
{
//....other code...
template
struct rebind
{ // convert an allocator<_Ty> to an allocator <_Other>
typedef allocator<_Other> other;
};
//....other code...
};
而在使用的时候的写法如下:
typename _Alloc::template rebind<_Node>::other _Alnod; typename是为了使用struct rebind存在,那么中间那个template呢?为什么要加那个template?从bnf分析的角度来看,似乎也无法解释它的存在我用的是VS.net2003,而我把这个问题交给我的数据结构老师后,他说他也无法说明这个问题,不过他说sgi等其他的STL中没有这样的用法,但VC++.Net中到处都是
请各路高手赐教。。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货