Code Room
Code reviewMediumcr-g169
Subject LifetimesLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ code that stores pointers to loop-local objects.

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 <vector>#include <string> std::vector<const std::string*> collect(const std::vector<int>& ids) {    std::vector<const std::string*> out;    for (int id : ids) {        std::string label = "id-" + std::to_string(id);        out.push_back(&label);    }    return out;}
Run or narrate your approach, then ask the coach.