由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Cannot use my own container as the underlying container of a stack? (c++)
相关主题
C++ templateC++ template question
如何 define/initialize static data member of a class templ谁给详细说一下这句
template question请问这是什么错误呀
一个C++ template的问题C++ linking 弱问 (one file)
template 类的继承问题问个c++的template的问题
Re: VC里面的stl支持是不是很弱?template 疑问
a c++ questionC++ template question
文一个简单的c++一个关于C++ template和overload的问题
相关话题的讨论汇总
话题: container话题: underlying话题: back话题: stack话题: type
进入Programming版参与讨论
1 (共1页)
d*******n
发帖数: 524
1
According to http://www.cplusplus.com/reference/stl/stack/
The underlying container may be any of the standard container class
templates or some other specifically designed container class. The only
requirement is that it supports the following operations:
* back()
* push_back()
* pop_back()
So I wrote my own "MyVector" to be used as an underlying container for the
stack. But it didn't work. Anybody knows the reason?
//---------------------------------------------------
#include<
d*******n
发帖数: 524
2
error info:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/
bits/stl_stack.h: In instantiation of 'std::stack >':
t.cpp:31: instantiated from here
Line 112: error: no type named 'value_type' in 'class MyVector'
compilation terminated due to -Wfatal-errors.

the

【在 d*******n 的大作中提到】
: According to http://www.cplusplus.com/reference/stl/stack/
: The underlying container may be any of the standard container class
: templates or some other specifically designed container class. The only
: requirement is that it supports the following operations:
: * back()
: * push_back()
: * pop_back()
: So I wrote my own "MyVector" to be used as an underlying container for the
: stack. But it didn't work. Anybody knows the reason?
: //---------------------------------------------------

z****e
发帖数: 2024
3
重写ctor。看看你自己是怎么定义的。
t****t
发帖数: 6806
4
you have to learn to read the error message -- it said ::value_type is
missing...not about ctor.

【在 z****e 的大作中提到】
: 重写ctor。看看你自己是怎么定义的。
t****t
发帖数: 6806
5
The synopsis of std::stack<> is shown below. Therefore, your Container
should satisfy:
typename Container::value_type;
typename Container::size_type;
Container::empty() const;
Container::size() const;
Container::top();
Container::top() const;
Container::push_back(const value_type&);
Container::pop_back();
namespace std {
template
【在 d*******n 的大作中提到】
: According to http://www.cplusplus.com/reference/stl/stack/
: The underlying container may be any of the standard container class
: templates or some other specifically designed container class. The only
: requirement is that it supports the following operations:
: * back()
: * push_back()
: * pop_back()
: So I wrote my own "MyVector" to be used as an underlying container for the
: stack. But it didn't work. Anybody knows the reason?
: //---------------------------------------------------

d*******n
发帖数: 524
6
So the short answer is: the following statement from cplusplus.com is
incorrect?
The underlying container may be any of the standard container class
templates or some other specifically designed container class. The only
requirement is that it supports the following operations:
* back()
* push_back()
* pop_back()

【在 t****t 的大作中提到】
: The synopsis of std::stack<> is shown below. Therefore, your Container
: should satisfy:
: typename Container::value_type;
: typename Container::size_type;
: Container::empty() const;
: Container::size() const;
: Container::top();
: Container::top() const;
: Container::push_back(const value_type&);
: Container::pop_back();

t****t
发帖数: 6806
7
It is correct. But you need to know how to read it. It said: "The underlying
*container* ..." where "container" is explicitly defined in the standard.
Container is defined in 23.1 -- it requires ::value_type and ::size_type
defined.
The original wording on the standard is:
"Any sequence supporting operations back(), push_back() and pop_back() can
be used to instantiate stack. In particular, vector (23.2.4), list (23.2.2)
and deque (23.2.1) can be used."
Similarly, the important word here is "seq

【在 d*******n 的大作中提到】
: So the short answer is: the following statement from cplusplus.com is
: incorrect?
: The underlying container may be any of the standard container class
: templates or some other specifically designed container class. The only
: requirement is that it supports the following operations:
: * back()
: * push_back()
: * pop_back()

1 (共1页)
进入Programming版参与讨论
相关主题
一个关于C++ template和overload的问题template 类的继承问题
请教一下这个template function在gcc下要怎么修改Re: VC里面的stl支持是不是很弱?
C++ template function typea c++ question
c++ template specialization 参数文一个简单的c++
C++ templateC++ template question
如何 define/initialize static data member of a class templ谁给详细说一下这句
template question请问这是什么错误呀
一个C++ template的问题C++ linking 弱问 (one file)
相关话题的讨论汇总
话题: container话题: underlying话题: back话题: stack话题: type