Recently, some readers came across an error message with the most annoying parsing error. This problem occurs for several reasons. Let’s discuss this now.
Repair your computer now.
anger is a counter-intuitive form of syntactic disambiguation in the C++ conversational language. In some situations, the C++ grammar cannot distinguish between creating a parameter object and specifying a function type on the phone. In these unavoidable situations, the compiler interprets the string as a type specification.
The term “most analysis” obnoxious was first used by Meyers Scott in his book STL Effective in 2001. Although rare in C, this phenomenon was true C++ until its creation did not spread with adaptation to initialization. in C++11.
A simple demo style appears when a function conversion is to convert an expression to a variable:
The initialized line 2 above is also ambiguous. Possible interpretation considers declaring a variable
i from an initial value created by returning
int. However, C allows extra parentheses around successful parameter declarations; In this case, the entry
i is instead a function declaration, which is equivalent to the following:
- different definition for
TimeKeeperinitialized with an anonymous instance of class
Timers< /code> or
- function declaration for a single
time_keeperfunction that returns an object of type
TimeKeeperand also has one parameter (without a name), since its type is a function (pointer really to a)[Note 1] that takes no input and returns
C++ requires a second interpretation, which is always incompatible with a line above 9. For example, clang++ warns that a number of pesky parsers have been applied to your line 9, and throws the following line as an error:
$clang++ time_keeper.cctimekeeper.cc:9:25: Warning: single square brackets are used in the function declaration. [-Wärger-parse] Time_keeper(Timers()); timer ^~~~~~~~~~timekeeper.cc:9:26: Note. Add a full pair of parentheses to declare your variable. TimeKeeper time_keeper(Timer()); ^ ( )timekeeper.cc:10:21: Error: The underlying member entry 'TimeKeeper (Timer Is (*)())' is not possible union structure Returns time_keeper.get_time(); safe ~~~~~~~~~~~^~~~~~~~~~
The overinterpretation of these declarations is rarely reserved. Function types in C++ are usually type definitions and are usually hidden have an explicit reference, possibly a pointer qualifier. To force the use of the primary alternate interpretation, a typical technique for usually alternate is the syntax for creating or modifying an object.
In the sample type conversion process, two different syntaxes are available for the cast: "C-style cast"
In each of our variable declaration examples, the primary preferred method (since C++11) of immutable is initialization (brackets). This  also allows trailing omission of the whole header type:
Prior to C++11, the usual methods that did the intended interpretation used extra parentheses and copy initialization:
In this last repeated syntax, the assignment can be expanded by the compiler. Since  is C++17, this optimization is guaranteed.