3 ms·
Yeah I expected a segfault too... but it didnt happen for me and printed fine so I was confused.
by rhodysurf 6y ago
Yeah I expected a segfault too... but it didnt happen for me and printed fine so I was confused.
- Jtsummers 6y agoTry putting it inside another function and then return the string_view before printing. The behavior will be more interesting. The first time I got "V", then consistently "f" or "+" after that. A lot of C++'s (and C's) memory "fun" doesn't readily appear when you're inside a particular function because the memory (like here) is on the stack. So your behavior within that function scope looks like what you want. Then you start returning values and, oops, something was a reference to memory on the stack. In which case it more or may not work depending on what else has happened between the value being placed on the stack and its use (I had to run a fun crash course for EEs on stack vs heap, when your only programming experience is a bit of Matlab this is not a topic you'll be familiar with).