I would assume the interviewer messed up and forgot to declare it and if I just not pretend to assume it was "left out for brevity" I would fail the interview as a smart ass.
There are so many layers to interviewing and you kinda need to guess what the intervoewer wants to hear.
In my defence, this is a HN comment thread and not an actual interview. I wrote that on my phone at 6pm on a Sunday.
We have an actual question, a snippet of code that is copied and shared to the candidate, and everyone who asks this question has undertaken this exercise. The interviewer has the list of (known) issues and a handful of stylistic things that can be talked about too. If we actually did share this snippet with someone and they said "should this be declared in the class body", I would say "oops yeah, thanks for catching", and update our template.
>you kinda need to guess what the intervoewer wants to hear
Interviewers are human, and I've done tech screens for probably 250 candidates over the past few years, and I've designed tech screens that have been used for probably 5x that. We have good days and bad days, and it's super tough to give an evaulation of someone in an hour. The main thing I'm looking for (and I tell people this) is someone that I think would be a good fit on the team. To me that means that their own read on their level is roughly equivalent to my read on their level (a senior engineer who says they understand concurrency but doesn't understand what a mutex or atmoic is is a fail, for example), and that they're not a giant pain in the ass. If you've managed to annoy me in an hour by assuming every single thing I do is an attempt to catch you out, we're not going to get along and I'm going to pass on you for that reason.
If ptr is some kind of global, then it makes sense for it not to be deallocated by the destructor? It’s apparently not really managed by this class, so why would its lifetime be tied to it?
I mean it’s psychotic to half-manage it like this but I don’t think the lack of a destructor is suspicious here; in fact I think it’s correct once the global pointer was introduced
IMHO, there are two review branches to discuss in this example:
First, if `ptr` is declared in the translation unit before and outside defining `class foo`, then there is no check for previous initialization and thus is likely a run-time defect.
Second, if `ptr` is not declared in the translation unit before and outside defining `class foo`, then it is likely a missing member definition and is a compile-time defect.
- ptr is not being deallocated in the destructor
(personal preference - use of class member without explicit `this->`)