Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

His reasoning is bogus. For his C equivalent, he writes:

> There are only two states. Not initialised object/memory where all the bets are off and the structure can contain random data.

He can get exactly the same effect by mimicking fstream interface: use constructors and destructors as they were meant to and introduce bool operator! to check whether the object has been successfully initialized.

In this scenario, only destructor needs to know about the "fail-constructed" state. Other methods don't need to implement the state-machine; calling them on "fail-constructed" object would be undefined, exactly as in his C version (e.g., calling foo_bar without calling foo_init and checking that it succeeded)!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: