I have a vector that contains lists, how do I add a new element list to the vector..without creating it beforehand.. i.e. , why can't I use the 'new' command like in java?
here is my code, which 'works'
Code:
#include<list>
#include<vector>
using namespace std;
class Graph {
private:
vector<list<int> > adjacencyList;
public:
Graph(int vertices)
{
for(int i=0;i<vertices;++i)
{
list<int> a;
adjacencyList.push_back(a);
}
}
};
why doesnt the following work?
Code:
#include<list>
#include<vector>
using namespace std;
class Graph {
private:
vector<list<int> > adjacencyList;
public:
Graph(int vertices)
{
for(int i=0;i<vertices;++i)
{
adjacencyList.push_back(new list<int>);
}
}
};
thanks!!