首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

2个STL有关问题请问(STL源码剖析中例子)

2012-06-05 
2个STL问题请教(STL源码剖析中例子)刚看STL源码剖析,里面例子中有如下代码:#include iostream#include

2个STL问题请教(STL源码剖析中例子)
刚看STL源码剖析,里面例子中有如下代码:

#include <iostream>
#include <cstddef>
using namespace std;

class alloc{
};
...

template <class T,class Ref,class Ptr,size_t BufSize>
struct __deque_iterator{
  typedef __deque_iterator<T,T&,T*,BufSize> iterator;
  typedef __deque_iterator<T,const T&,const T*,BufSize> const_iterator;
....
}

template <class T,class Alloc=alloc,size_t BufSize=0>
  class deque{
public:
  typedef __deque_iterator<T,T&,T*,BufSize> iterator;
};

问题1:此处定义的空类alloc有什么含义?起什么作用?
问题2:typedef __deque_iterator<T,T&,T*,BufSize> iterator; 这里跟上面参数声明的类型不一致,是否有问题?
  用法怎样?

麻烦说详细点,看C++98标准中的template全是E文的,又太多了,实在看不过来。
谢了!


[解决办法]
typedef __deque_iterator<T,T&,T*,BufSize> iterator;
typedef __deque_iterator<T,const T&,const T*,BufSize> const_iterator;我不知道你是不是问这两个,这两个是用不同的类型实参实例化不同的模板!生成不一样的模板的


 class deque{
public:
typedef __deque_iterator<T,T&,T*,BufSize> iterator;
};

中的作用域和上面两个不同 不存在什么不一致问题
[解决办法]
ALLOC是内存分配器, 支持allocate/dellocate接口, 你也可以写自己的内存池, STL默认使用自己的一个全局内存池.

热点排行