This program is taken from cplusplus.com
#include <iostream>
#include <vector>
#include <deque>
#include <stack>
using namespace std;
int main ()
{
deque<int> mydeque (3,100); // deque with 3 elements
vector<int> myvector (2,200); // vector with 2 elements
stack<int> first; // empty stack
stack<int> second (mydeque); // stack initialized to copy of deque
stack<int,vector<int> > third; // empty stack using vector
stack<int,vector<int> > fourth (myvector);
cout << "size of first: " << (int) first.size() << endl;
cout << "size of second: " << (int) second.size() << endl;
cout << "size of third: " << (int) third.size() << endl;
cout << "size of fourth: " << (int) fourth.size() << endl;
return 0;
}
What I failed to understand is, why are we mentioning stack<int, vector<int>> i.e. two data types rather than just stack<vector<int>>?
Check out: http://www.sgi.com/tech/stl/stack.html
Creating a stack with two data type parameters to the template as so
stack<T, Sequence> stack;is done because the first type parameter is the type of element the stack holds, and the second type parameter is the container type used to implement the stack.
Using different container types gives you different memory allocations, benefits and drawbacks in terms of speed, etc. It’s just giving you as the consumer more flexibility in terms of the type of implementation you wish to use.
From that link: