Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

david_williams

std::vector of std::vectors?

This topic is 5853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Just a quick question, how do you create an std::vector where each element is an std::vector? I tried std::vector <std::vector<Polygon>> polyList; but it didn't compile. Any ideas? [EDIT - I edited the code line to make it show up, but didn't change the spacing so that Sneftel's answer is still correct and makes sense. ] [edited by - Kylotan on September 12, 2002 7:58:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
A template can only be templated of a solved template.

If brute force does not solve your problem....you''re not using enough!

Share this post


Link to post
Share on other sites
When nesting template specifications, put a space between adjacent angle brackets, or the compiler will recognize it as another operator.


  
vector<vector<int>> v; // NO!!!


vector<vector<int> > v; // YES!!!




Don't listen to me. I've had too much coffee.

[edited by - sneftel on September 12, 2002 7:53:18 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Because >> is parsed as a single token. This is necessary. e.g. for vector<std::bitset<1>>3> >. If >> was considered the end of the template, this would be illegal code.



This is because C++ parses the largest token possible, yes? So

++++a;

would be

++(++a);

and

+++++a;

would be

++(++(+a));

right?

Share this post


Link to post
Share on other sites
Hold that thought, I remember a huge e-mail our head programmer at work wrote on the subject...

I think what he said is that the compiler parses the file for tokens first and then resolves what''s actually going on... or something to that effect...

Share this post


Link to post
Share on other sites
quote:
Original post by Zipster
Hold that thought, I remember a huge e-mail our head programmer at work wrote on the subject...

I think what he said is that the compiler parses the file for tokens first and then resolves what''s actually going on... or something to that effect...


Right. It tokenizes it before it does stuff with it. Which means it''s okay that angle brackets look like greater-than and less-than, since context can determine which is which, but once you''re actually doing stuff with the tokens, it''s already too late to decide that your bitwise shift is actually two angle brackets.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Yeah, the lexer can more easily tell it is in a template context when it''s opening the template parameter block, because it either has ''template'' or ''typename Foo'' (or ''class Foo'') before, than when it is closing it, since it can have an integral parameter ( case of bitset<10> ) for which both the bitshift and the two template endings would be valid tokens. In the interest of being able to write the previously posted code, the bitshift has been decided to take precedence.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!