Code Room
Code reviewHardcr-g167
Subject Use after freeLevel Senior–Staff~30 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ async registration using a lambda.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewcpp
#include <functional>#include <string> struct Worker {    std::string name;    void schedule(std::function<void()>& slot) {        slot = [this]() { use(name); };    }    void use(const std::string& s);}; std::function<void()> g_slot;void wire() {    std::function<void()> tmp;    { Worker w{"alpha"}; w.schedule(reinterpret_cast<std::function<void()>&>(tmp)); }    g_slot = tmp;    g_slot();   // invoked later}
Run or narrate your approach, then ask the coach.