vkumar
vkumar

Reputation: 5

How to define a collection of stack objects?

I am wondering if I can define a set of stack objects inside as part of list or vector? What I am trying to do is defining a collection of stack objects which I can get and add like normal int or float type inside one of STL containers. For example: vector<stack> stackCollection But it gives me error: use of class template 'stack' requires template arguments.

Is there any way to do this in c++?

#include <iostream>
#include <stack>
#include <vector>
#include <list>

using namespace std;
int main() {
    vector<stack> stackCollection;
    //vector<int> stackCollection;
    return 0;
}

Upvotes: 0

Views: 45

Answers (1)

njp
njp

Reputation: 31

You have to specify which type the stack should contain, like this:

vector<stack<int>> stackCollection;

Upvotes: 3

Related Questions