0

Possible Duplicate:
For nested templates, when did `>>` become standard C++ (instead of `> >`)?
Why did templates of templates (e.g. vector<vector<int> >) require a space between the closing angle brackets prior to C++0x?

I am simply trying to create a vector:

vector<Transform3D<double>> tempVector;

This is the compilation error i get:

/../main.cpp:34:26: error: a space is required between consecutive right angle brackets
  (use '> >')
vector<Transform3D<double>> tempVector;
                         ^~
                         > >

What does not make is sense is, why the problem is solved by changing the vector to as the error describes:

vector<Transform3D<double > > tempVector;

Why is vector<Transform3D<double>> and vector<Transform3D<double > > not identical?

Community
  • 1
  • 1
JavaCake
  • 4,075
  • 14
  • 62
  • 125
  • Prior to C++11, the `>>` would likely confuse the compiler as being the `>>` operator. – wkl Dec 25 '12 at 17:32

2 Answers2

2

They aren't identical (at least prior to C++11) because the last >> characters are parsed as a single operator (operator>>). Putting a space between them causes the expected behavior.

The same situation happens where the compiler parses <: as the beginning of a tigraph/digraph. For example:

N<::T> // <: parsed as [

A space separating the operators causes the code to work fine.

David G
  • 94,763
  • 41
  • 167
  • 253
1

Because >> is a bit shift operator, a newer compiler can distinguish the two though.

demorge
  • 1,097
  • 1
  • 7
  • 17