1

I realize there are better compilers out there but I have preferred to stick with vc6, every once in a while, I find weird flukes and was wondering if this one is localized to my installation or everyone's.

Keep in mind that the compiler in question is:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
(the linker, etc not relevant since this question doesnt seem to involve them)

Tried declaring a class inheriting from std::vector, which works fine, unless you also try to be specific with defining the second template parameter:

10: class foo : public std::vector<LPTSTR,std::allocator<LPTSTR>>
11: {
12:   public:
13:   foo();
14:   ~foo();
15: };

does not compile and gives this error: c:\foo\foo.h(10) : error C2143: syntax error : missing '>' before '{'

now, the real question is, WHY is this legal:

10: class foo : public std::vector<LPTSTR,std::allocator<LPTSTR>>> 
11: {
12:   public:
13:   foo();
14:   ~foo();
15: };

note the extra > at the end of line 10... and what I want to know is:

  1. did I do something wrong?
  2. is this only happening with my install?
  3. should I refrain from the workaround because it could cause problems later somehow?

I tried to research this as much as possible but as most programmers know it isn't so easy to search online because the search engines seem far to limited without even regular expression searches it becomes hit-or-miss and/or a popularity contest (is the topic of interest popular enough to be ranked up on Google, etc).

I thank you much in advance for your prompt (or even not prompt) reply on this one. I try to answer questions to others even if it seems ridiculously easy to me and try to remember knowledge always starts with lack of knowledge.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • You should not inherit from standard library containers: http://stackoverflow.com/questions/922248/is-there-any-real-risk-to-deriving-from-the-c-stl-containers. – Jon May 08 '12 at 10:15
  • 1
    The inability to parse `>>` correctly for template definitions is a shitty bug in VS6 which has been fixed since VS 2005 onwards so you have to place a space between them like `> >`, however your second error is inexplicable other than parser error – EdChum May 08 '12 at 10:26
  • @EdChum I am not sure the standard required `>>` to parse correctly for templates pre-C++11. – juanchopanza May 08 '12 at 10:31
  • @juanchopanza I can't quote the standard but I know this was something that Bjarne lamented in compilers prior to C++11 and C++03 so I think it should've been handled, I don't know about other compilers but this was a known problem with MS compilers – EdChum May 08 '12 at 10:44
  • @EdChum gcc doesn't swallow that without the C++11 flag. I think Bjarne S. was lamenting that the standard didn't enforce the correct parsing because it was deemed at the time that it would be too much to ask from compilers, or something like that. – juanchopanza May 08 '12 at 11:12

2 Answers2

5

It probably means that your compiler isn't parsing the >> symbol as you expect, i.e it isn't supporting C++11 in this respect.

Try this

std::vector<LPTSTR,std::allocator<LPTSTR> >
                                         ^ note space

and also read up on why it might not be a good idea to inherit from a standard library container.

As for the question "why is >>> legal", well, it isn't legal at all, not on C++03, not on C++11. I can only conclude that it is a feature of your compiler.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
4
class foo : public std::vector<LPTSTR,std::allocator<LPTSTR>>

does not compile, because >> is treated as a one token and you should separate closing brackets with space. That was fixed in C++11.

Also, you should not inherit from std containers, because they were not designed for that (for example they doesn't have virtual destructors).

Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79