Remix.run Logo
tempaccount5050 3 hours ago

Holy shit, I didn't know that.

Circa 2004 I was in college and took a C++ class. I spent an entire week trying to get my final project working and couldn't for the life of me figure out what was wrong. It was only a few hundred lines and was like an employee record type demo. I spent about 3 hours one on one with the professor trying to figure it out. I remember that removing the auto_ptr stuff and using regular pointers would make it work (because the problem has to be with the pointer stuff right?), but part of the requirements was that I had to use auto_ptr because it was safer or whatever.

We tried compiling it on different systems and nothing would get it to work. He ended up giving me a C on the project admitting "it should work, but that doesn't cut it in the business world" or something to that effect which really pissed me off.

I just had a chat with GPT about this and that was almost certainly what was causing my program to segfault.

std::auto_ptr<int> a(new int(5));

std::auto_ptr<int> b = a; // a becomes null

Wild.