Search code examples
c++vector

Template issue with vector


Possible Duplicate:
For nested templates, when did `>>` become standard C++ (instead of `> >`)?

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?


Solution

  • 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.