How to delete the default constructor?

后端 未结 4 711
耶瑟儿~
耶瑟儿~ 2021-02-02 06:00

Sometimes I don\'t want to provide a default constructor, nor do I want the compiler to provide a system default constructor for my class. In C++ 11 I can do thing like:

4条回答
  •  星月不相逢
    2021-02-02 06:32

    Sure. Define your own constructor, default or otherwise.

    You can also declare it as private so that it's impossible to call. This would, unfortunately, render your class completely unusable unless you provide a static function to call it.

提交回复
热议问题