简体   繁体   English

cpp迭代器问题

[英]cpp iterator problem

template<class T>
    class mStack
    {
    private:
       vector<T> a; 
       vector<T>::iterator top;
    public:
       void push(T);
       T pop();
       mStack();
       void printStack();
};

The code with above class is not getting compiled... why? 上面类的代码没有得到编译...为什么? What is the problem? 问题是什么? The compiler says "expected ; above top". 编译器说“ expected; top top”。

You need a typename: 您需要一个类型名称:

typename vector<T>::iterator top;

This reassures the compiler thar vector<T> really is a type. 这可以确保编译器thar vector<T>确实是一种类型。 For a discussion of this and other template gotchas, see the C++ FAQ . 有关此模板和其他模板陷阱的讨论,请参见C ++ FAQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM