我试图向我的类添加一些类型定义,但是编译器在以下代码中报告了一个语法错误:
template<class T>
class MyClass{
typedef std::vector<T> storageType; //this is fine
typedef storageType::iterator iterator; //the error is here但下一种方法也不起作用:
typedef std::vector<T>::iterator iterator;我在许多论坛上寻找答案,但我找不到解决方案或解决办法。谢谢你的帮助!
发布于 2012-10-20 00:04:05
您缺少一个typename
typedef typename std::vector<T>::iterator iterator;类似的问题还有很多。例如,看看下面的内容:
发布于 2012-10-20 00:05:44
std::vector<T>::iterator是一个依赖类型,所以您需要在它之前添加typename。
typedef typename std::vector<T>::iterator iterator;
^https://stackoverflow.com/questions/12978137
复制相似问题