[1] a right angle bracket> Improvement
In C ++ 98, there is a need to circumvent the rules:
If there is a continuous two right angle brackets> when instantiating the template, you need a space between them to separate in order to avoid the occurrence of errors during compilation. Examples are as follows:
1 // Example 1: Nested template ID 2 Template < int I> class X-{}; . 3 Template < class T> class the Y {}; . 4 the Y <X-< 1 >> X1; // compiled successfully . 5 the Y < X-< . 1 >> X2; // compilation failure . 6 . 7 // example 2: cast . 8 const Vector < int > V = static_cast <Vector < int >> (V); // compiled successfully . 9 const Vector < int > V static_cast = <Vector < int>> (v); // fail to compile
Such restrictions, in the new C ++ 11 standard was canceled.
However, these "smart" the judge will bring interesting incompatibility with some of the C ++ 98.
For example, users just want >> represented in the instance of the template is truly the right, but C ++ 11 will resolve it as a template parameter delimiter. Examples are as follows:
. 1 Template < int I> class X-{}; 2 X-< . 1 >> . 5 > X; // compilation failure . 3 X-<( . 1 >> . 5 )> X; // successfully compiled
Using the C ++ 98 standard compiled, then this example will compile.
Because the compiler that X <1 >> 5> x; double angle is a shift operation, the final shape can be obtained as a template instance X <0> x's.
If a compiled C ++ 11 standard, then the programmer will alert get a compiler error because the compiler preferentially after the first bicuspid brackets> and X <been paired.
Although few people to be displaced operate simultaneously when the template is instantiated, however, C ++ 98 and C ++ 11 does not compatible syntactically at this point.
To avoid such incompatibilities are also very simple to use parentheses "1 >> 5" quotes (such as the compiler examples of success in writing) to ensure that the right has priority, there would not be a similar problem.
good good study, day day up.
Select the cycle order summary