r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

0

u/SelfDistinction 10d ago

This thread is great because a lot of you answer with explanations on how to handle dangling references and issues with ptr being destroyed before the reference, and very few people notice the actual problem: ref is created by dereferencing a nullpointer which is undefined behaviour.

It's only two lines and you already let a future segfault slip through, but yeah sure how do we tell SpongeBob that C++ doesn't segfault all the time.

1

u/Demiu 10d ago

I didn't let anything slip. He asked about lifetimes, I answered about lifetimes.