Stop C++ Class Instantiation

元气小坏坏 提交于 2019-12-06 02:07:09

Throwing an exception is really the only way to indicate an error during construction.

http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.8

If the connection can normally fail, set a flag in the object and provide an is_connected() member function for the class, and use it in your application code. If it normally cannot fail, throw an exception. The former is the pattern that the C++ Standard Library uses for opening file streams.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!