4 ms·
Why are some examples full of errors? The `set_vec` method for instance does not bind the reference, you can't change the reference itself... so the code would
by cocoto 9mo ago
Why are some examples full of errors? The `set_vec` method for instance does not bind the reference, you can't change the reference itself... so the code would simply copy the vector and there would be no dangling reference... And `B` is missing a constructor since the default constructor would be ill-formed (you can't default initialize a reference).
Anyway the article is quite approachable, do not take my criticism to shy away from writing!
- pixelesque 9mo agoYeah, that example's totally wrong, as you say, the std::vector<int> would get copied by value, so there'd be no issue at all.
- tialaramex 9mo agoI strongly encourage people writing textual examples in 2026 to use Compiler Explorer. https://cpp.godbolt.org/ https://cpp.godbolt.org/ Matt Godbolt's tool lets your reader play with your examples and learn more about what's going on. As a bonus, if it doesn't compile and work in Compiler Explorer now you know early before you hit "publish". It's the same reason you should run a spellchecker, raweht thun jstu hope forr th bess