模板<t>类</t>中T的向量向量

时间:2010-03-15 15:51:47

标签: c++ templates vector std stdvector

为什么这段代码不能编译(Cygwin)?

#include <vector>

template <class Ttile>
class Tilemap
{
    typedef std::vector< Ttile > TtileRow;
    typedef std::vector< TtileRow > TtileMap;
    typedef TtileMap::iterator TtileMapIterator; // error here
};
  

错误:输入std::vector<std::vector<Ttile, std::allocator<_CharT> >, std::allocator<std::vector<Ttile, std::allocator<_CharT> > > >' is not derived from type Tilemap'

1 个答案:

答案 0 :(得分:4)

因为还不知道TtileMap::iterator是一种类型。添加typename关键字以修复它

typedef typename TtileMap::iterator TtileMapIterator;
相关问题