4 ms·
> don't separate declaration from assignment and it will never be unassigned That's tricky when you want to write algorithms where you can start with an uninit
by wavemode 1y ago
> don't separate declaration from assignment and it will never be unassigned
That's tricky when you want to write algorithms where you can start with an uninitialized object and are guaranteed to have initialized the object by the time the algorithm completes. (Simplest example - create an array B which contains the elements of array A in reverse order.)
You can either allow declaring B uninitialized (which can be a safety hazard) or force B to be given initial values for every element (which can be a big waste of time for large arrays).
- Maxatar 1y agoI don't think that's much of an issue. If you need deferred initialization then stick to a pointer and then once the pointer is initialized shadow it with a reference. int* pre_foo = null; ... initialize pre_foo ... int& foo = *pre_foo;