Are ={} and {}-style initializations the same in C++11?

前端 未结 3 1206
野趣味
野趣味 2021-01-02 01:05

C++11 introduced {}-style initializations. But are these two forms

T x {...};
T x = {...};

the same?

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 01:18

    The syntax when using them in one case means different things

    struct A { };
    
    namespace X {
      struct A final {};
      struct A final = {};
    }
    

    In the first case, we are defining a struct called A, and in the second case we are defining an object called final.

提交回复
热议问题