问题描述
我只是想创建一个向量:
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.
这篇关于矢量模板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!