Why doesn't this enum convert to int?

后端 未结 3 840
陌清茗
陌清茗 2020-12-14 07:21

Why does the following code not compile under g++ (C++14), MSVC (C++14), or ARM (C++03)?

The named Error instance calls the integer constructor, but the anonymous Er

3条回答
  •  感情败类
    2020-12-14 08:11

    This comes from the same place as "The Most Vexing Parse" - the rule that if it can be a declaration, it is a declaration.
    And surprisingly, you're allowed to put parentheses around the identifier in a variable declaration.
    (I have no idea why, but I'm guessing that it simplified C's parser back in the day.)

    The following are all valid declarations of int variables:

    int (foo);
    int (bar) = 0;
    int (baz)(3);
    int (twaddle)(baz);
    

提交回复
热议问题