繁体   English   中英

使用STL的列表对象创建堆栈

[英]Using STL's list object for Stack creation

我想在C ++中创建堆栈列表,但是编译器给了我一些错误消息:

 #include <list>
    #include <stack>

    class cName
    {
        [...]
        list<stack> list_stack;
        [...]
    }

错误:

error C2143: syntax error : missing ';' before '<'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2238: unexpected token(s) preceding ';'

std :: stack是模板,您需要将其与模板参数一起使用。 样品:

class cName
{
  typedef int ConcreteType;
  std::list<stack<ConcreteType> > list_stack;
                  ^^^^ use it with real type
};

堆栈也被模板化,因此应该

list<stack <...> > list_stack;

如果您希望堆栈只处理一种类型,例如int,请将代码中的stack更改为int

list<int> list_stack;

否则,您应该创建自己的模板类型,而不要使用stack

template <class T> 
class List
{
    list<T> list_stack;

    T top();
    void push(T v);
};

暂无
暂无

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

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