Typedef矢量模板
typedef vector template
本文关键字:Typedef 更新时间:2023-10-16
我正在尝试在我的课程中添加一些类型,但是编译器在以下代码上报告了语法erron:
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;
我一直在寻找许多论坛上的答案,但是我找不到解决方案或解决方法。谢谢您的帮助!
您缺少typename
:
typedef typename std::vector<T>::iterator iterator;
有很多类似的问题。例如。查看以下内容:
- C 模板键入迭代器
std::vector<T>::iterator
是一种依赖类型,因此您需要在它之前添加TypeName。
typedef typename std::vector<T>::iterator iterator;
^
相关文章:
- C++:TypeDef使用元组
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 为什么在使用typedef时类推导指南会失败
- 尝试根据类中 typedef 的存在来专门化模板函数
- 如何重新定义MPI_FLOAT,MPI_DOUBLE以 typedef 的方式
- typedef 枚举和枚举类有什么区别?
- 在类模板中使用 typedef 时出错
- 模板类中的 typedef 语句
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- 向前声明指向类的 typedef 指针
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何创建 typedef 结构的前向声明
- 从 Typedef 数据类型中删除常量
- typedef vector size_type in header file
- typedef 别名的析构函数
- 如何使用 typedef 创建多个数组?
- 使用智能指针指向 C 库中的结构,该结构通过 typedef 隐藏实现(即不完整的类型)
- 模板类编译问题与 typedef 变量