我在这里想念的是什么

时间:2014-03-09 17:48:19

标签: c++ templates

    #include<iostream>
    #include<stdlib.h>
    using namespace std;

    template<class T, unsigned int ssize =100 >
    class StackTepmlate{
        T StackTepmlate[ssize];
        int top;
    public:
        StackTepmlate() : top(0){}
        void push(const T& i){
            if(top >= ssize) cerr <<"Too many push()es\n";
            else stack[top++]=i;
        }
        T pop(){
            if(top<=0) cerr<<"Too many pop()s\n";
            else return stack[--top];
            exit(1);
        }

        class iterator;
        friend class itertor;
        class iterator{
            StackTepmlate& s;
            int index;
        public:
            iterator(StackTepmlate& st):s(st), index(0){}
            iterator(StackTepmlate& st,bool):s(st),index(s.top){}
            T operator*() const {return s.stack[index];}
            T operator++(){
                if(index >= s.top) cerr<<"iterator moved out of range\n";
                return s.stack[++index];
                exit(1);
            }
            T operator++(int){
                if(index >= s.top) cerr<<"iterator moved out of range\n";
                return s.stack[index++];
                exit(1);
            }
            bool operator==(const iterator& rv) const{
                return index==rv.index;
            }
            bool operator!=(const iterator& rv) const{
                return index!=rv.index;
            }
            friend ostream& operator<< (ostream& os, const iterator& it){
                    return os<<*it; // Line 47 - Intellisense error
            }
        };
        iterator begin(){return iterator(*this);}
        iterator end(){return iterator(*this,true);}
    };

IntelliSense:多个运营商“&lt;&lt;”匹配这些操作数:第47行

第7行的其他错误:

  • 错误1:C2461:'StackTepmlate':构造函数语法 缺少形式参数7
  • 错误2:C2461:'StackTepmlate': 构造函数语法缺少形式参数

缺少我让T工作的选项:

  1. 复制ctor
  2. 默认ctor
  3. 运营商=
  4. 运营商==
  5. 运营商&lt;&lt;
  6. Operator ++
  7. 运营商 -
  8. 收回int的ctor
  9. a recive void *
  10. 谢谢!

0 个答案:

没有答案