4 ms·
Nice example! I think that can be simplified: node a(nil, nil, 0); node b(a, a, 2); new(&a) node(b, b, 1); One thing I am not 100% sure about is whether
by Someone 12y ago
Nice example! I think that can be simplified:
node a(nil, nil, 0);
node b(a, a, 2);
new(&a) node(b, b, 1);
One thing I am not 100% sure about is whether the standard guarantees that those references to the old 'a' are valid references to the new 'a'.
Also, the above works in the general case where there is a nontrivial destructor or when the runtime checks the validity of those references or traverses them at destruction time (might happen when running under a tool looking for memory leaks, for instance, or when using a reference-counting garbage collector under the hood)
- evincarofautumn 12y agoThe standard doesn’t seem to specify it directly, but I think your simplification is also correct.