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<
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
7 楼
重写ctor。看看你自己是怎么定义的。
t*t
8 楼
you have to learn to read the error message -- it said ::value_type is missing...not about ctor.
【在 z****e 的大作中提到】 : 重写ctor。看看你自己是怎么定义的。
t*t
9 楼
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
10 楼
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
11 楼
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()