C++: Constructor versus initializer list in struct/class

前端 未结 2 453
梦如初夏
梦如初夏 2021-01-12 01:11

An object of a struct/class (that has no constructor) can be created using an initializer list. Why is this not allowed on struct/class wit

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 01:40

    If by your question you mean to ask, "Can I do this:"

    struct MyGizmo
    {
      char things_[5];
      MyGizmo() : things_({'a', 'b', 'c', 'd', 'e'}) ();
    };
    

    ...then the answer is no. C++ doesn't allow this.

提交回复
热议问题