5

I can do a simple array of sets: set < char > * words = new set < char > [10] How I can do a vector of sets? This results in a compiler error: vector < set< char >> v . Thank you for answers!

hivert
  • 10,579
  • 3
  • 31
  • 56
Zhake
  • 71
  • 1
  • 4
  • 1
    Repeating the title in the question is not recommended and it is a poorly ask question. Add details, code you have tried, examples you have seen, what you are trying to accomplish etc. – Joe Apr 08 '11 at 19:03
  • Please explain what you're trying to do and what you mean by `dynamic array of sets`. – Alexander Gessler Apr 08 '11 at 19:03
  • `vector > arrSets;` This will create a dynamic array (`vector`) of sets. Is that what you are asking? – Naveen Apr 08 '11 at 19:09
  • @Naveen: He'd probably want vector< shared_ptr< set< T > > > to avoid copying sets around needlessly. – Jollymorphic Apr 08 '11 at 19:14
  • 1
    (They did the sets) They did the vec-tor of sets! (They did the sets) It was pure programming sex! – Potatoswatter Apr 08 '11 at 19:29
  • `vector < set< char >> v` doesn't work because the compiler treats the `>>` as the right shift operator. Put a space between the two `>` like so: `vector < set< char > > v`. – Emile Cormier Apr 08 '11 at 19:34
  • 2
    Isn't it obvious that he's wondering why the `>>` is causing an error? I fixed the wording a bit. Seems like a legitimate question to me. Voting to re-open. – Emile Cormier Apr 08 '11 at 19:39
  • … also because OP added the example code shortly *after* it was closed. – Potatoswatter Apr 08 '11 at 20:05

2 Answers2

8

If vector < set< char >> v is exactly what you've got there (I hope you cut and pasted), you've run into one of the annoying little features of C++.

Those >> look to you like two closing angle brackets for two templates. They look like a right shift operator to the compiler. Change them to > > with a space in between.

Fortunately, this is being addressed in the C++ standard that should be ratified this year. Unfortunately, you aren't working with a C++11-compliant compiler just now.

David Thornley
  • 56,304
  • 9
  • 91
  • 158
2

Instead of '>>' try '> >'... like so:

vector<set<char> > testVect;
poy
  • 10,063
  • 9
  • 49
  • 74