3 ms·
You'll get a run time error.
by SamReidHughes 10y ago
You'll get a run time error.
- lmm 10y agoMaybe. Or maybe you'll get an invisible resource leak, or silent data corruption, or an RCE vulnerability.
- SamReidHughes 10y agoWell I don't know about that. If you have a datatype whose constructors can't throw, it should still assert at run time about its state that it's been initialized. Like, you have to actually do that, of course. So there's more surface area for mistakes inside the object, but from the outside of the object, which is what I think this sub-thread is talking about, they get caught at run time.
- lmm 10y agoIt shouldn't have to be assertions though - you should make it correct by, well, construction. When the fields are RAII the constructor can just initialize them. If your class has different possible states and flags it's usually correct to promote the different states to differnt types (subclasses).
- SamReidHughes 10y agoI don't think we're disagreeing about anything. The scope of my comment is in reference to "So how do you protect yourself against inadvertently passing around uninitialized objects?" The answer is, with a run-time error.