[英]Template class accepting std::vector<T> or std::array<T>
[英]Vector of vectors of T in template<T> class
为什么此代码无法编译(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
Tilemapstd::vector<std::vector<Ttile, std::allocator<_CharT> >, std::allocator<std::vector<Ttile, std::allocator<_CharT> > > >' is not derived from type
'
因为尚未知道TtileMap::iterator
是一种类型。 添加typename
关键字进行修复
typedef typename TtileMap::iterator TtileMapIterator;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.