5 ms·
So what is wrong with { object* p=NULL; p = new object(); p->foo() delete p; } Do they just mean the missing semicolon? If so that's a pretty lame
by lacker 18y ago
So what is wrong with
{
object* p=NULL;
p = new object();
p->foo()
delete p;
}
Do they just mean the missing semicolon? If so that's a pretty lame interview question.
- aminuit 18y agoYou omitted a line. { object* p=NULL; p = new object(); p->foo() delete p; } // ?? Whats wrong with above 1) Missing a semi-colon. 2) The developer knowingly checked in broken code as evidenced by the comment. 3) In English the question mark comes at the end of the sentence.
- brc 18y agoIn the age of instant syntax error feedback, it's exceedingly lame. Here's the formula for getting a 6 figure developer job. 1) learn your craft 2) get experience 3) be pleasant and productive Answering crappy interview questions doesn't really come into it. It's as if the author thinks the thing that separates success from failure is knowing the answer to gimmicky questions.
- andylei 18y agoThere are many elements of getting a 6 figure developer job. The things you mentioned are important, but answering interview questions are important as well. If you can't answer interview questions, you can start up (nothing wrong with that), but you won't be able to land jobs.
- brc 18y ago"but answering interview questions are important as well" Agreed - it's very important to interview well. answering crappy and stupid interview questions : Disagree strongly. Anyone asking these idiotic questions 'why are manhole covers round?' is more likely trying to prove to themselves how clever they are at asking tricky questions than finding the candidate with the right fit and skills.
- xiaoma 18y agoAt least here in Taipei, most manhole covers I see are rectangular. What kind of interview question is that?
- edw519 18y agoIt's unclear from such a small snippet whether "p" is a local or global variable. Either way, have a little consideration for the next programmer and give it a meaningful name of at least 3 characters. Make it easier to read and search for. And dust the "foo" and give it a meaningful name, too.
- neilc 18y agofoo() might throw an exception, leaking "p". Stack allocation should probably be used instead of heap allocation here, anyway.
- brl 18y agoThanks for reminding me why I'm never going anywhere near C++ ever again in my life. Good answer though, I was stumped.
- lacker 18y agoUgh. Good point though. Reminds me of why my company forbids the use of exceptions in C++ programming.
- aminuit 18y agoI totally missed it too. People are using this to bash C++ which is probably fair, but it's worth noting that lots of modern C++ folks default to using RAII pointer types (std::auto_ptr, boost::shared_ptr) to guard against these types of errors.
- deleted 18y ago[deleted]
- deleted 18y ago[deleted]