Ziyao Wei Ziyao Wei - 1 year ago 152
C++ Question

Template within template: why "`>>' should be `> >' within a nested template argument list"

I know that when we are using template inside another template, we should write it like this:

vector<pair<int,int> > s;

and if we write it without the whitespace:

vector<pair<int,int>> s;

we will get an error:

`>>' should be `> >' within a nested template argument list

I see this is understandable, but I just can't help but wondering, in which cases will this be really ambiguous?

Answer Source

Sometimes you want it to be >>. Consider

boost::array<int, 1024>>2> x;

In C++03 this successfully parses and creates an array of size 256.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download