矢量模板问题 [英] Template issue with vector

查看:90
本文介绍了矢量模板问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
对于嵌套模板,何时>>`成为标准的C ++(而不是`>>`)?
为什么模板的模板(例如vector< vector<; int>>)在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;

为什么 vector< Transform3D< double>> vector< Transform3D< double>> 不同吗?

推荐答案

它们是不相同的(至少在C ++ 11之前),因为最后一个>> 字符被解析为单个运算符( operator>> ).在它们之间放置空格会导致预期的行为.

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.

这篇关于矢量模板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆