【发布时间】:2012-05-25 13:59:01
【问题描述】:
为什么以下内容无法编译(MSVC10 - 但我怀疑它不是有效的 C++),是否有解决方法?
template <typename M>
struct MyClass
{
typedef std::vector<M>::iterator iteratorT;
iteratorT myIterator;
};
错误是error C2146: syntax error : missing ';' before identifier 'iteratorT'。我尝试了一堆变体,结果相同:您可以将std::vector<M>::iterator 用作成员函数中的类型,但不能用作成员变量的类型。
【问题讨论】:
-
一个相当常见的常见问题解答。见这里parashift.com/c++-faq-lite/templates.html#faq-35.18
-
谢谢 - 我不知道要搜索什么才能找到答案!