0

I want to create 9 sets and put them in vector.The following code error outs

class X{
   vector<set<int> > rowset(9,set<int>());
};
Line 2: expected identifier before numeric constant

Following works ok. But i want to insert empty sets in vector so that i don't have to do a push_back. Please suggest why the above code is erroring out.

class X{
   vector<set<int> > rowset;
};
David
  • 4,634
  • 7
  • 35
  • 42

2 Answers2

2

What about:

class X{
  X():rowset(9,set<int>()){}
  vector<set<int> > rowset;
};
uvgroovy
  • 453
  • 3
  • 9
2

Use this:

vector<set<int> > rowset = vector<set<int> >(9, set<int>());

...or that:

vector<set<int> > rowset{vector<set<int> >(9, set<int>())};

More information on these questions, similar to yours:

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56