4 ms·
How about this: class Foo { void Foo() { this.error = true/false; } bool constructed() { return this.error } }
by speedplane 8y ago
How about this:
class Foo {
void Foo() {
this.error = true/false;
}
bool constructed() {
return this.error
}
}
- dymk 8y agoThis is how you get the equivalent of `if err != nil { return err; }` everywhere in your codebase. We've already come to the conclusion that this pattern is terrible. What you really need is to separate object allocation from construction. But then you're adopting an object model that C++ just doesn't support.
- jcelerier 8y agoIt sucks versus Foo() { if(...) throw whatever; }. It needs more code (check for constructed() every time, and if you forget to checking it you've introduced a bug), and is less performant (since you will have one additional branch in the "if(constructed())" mandatory check.
- Koshkin 8y agoThe ‘error’ member variable would take an additional space in the object that otherwise could be as small as a byte. C++ is carefully designed to avoid unnecessary overhead.
- iainmerrick 8y agoExceptions take space.