gpt4 book ai didi

c++ - template 类中 T 的 vector 的 vector

转载 作者:行者123 更新时间:2023-11-27 23:34:01 24 4
gpt4 key购买 nike

为什么这段代码无法编译 (Cygwin)?

#include <vector>

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

error: type std::vector<std::vector<Ttile, std::allocator<_CharT> >, std::allocator<std::vector<Ttile, std::allocator<_CharT> > > >' is not derived from typeTilemap'

最佳答案

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

typedef typename TtileMap::iterator TtileMapIterator;

关于c++ - template<T> 类中 T 的 vector 的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2448463/

24 4 0