compilation - C++ compiler gives unitialized variable warnings when declared in if-else statements -
i'm sure there's easy explanation this, have code this:
routingtablepoolentry rtpe; routingtablepoolentry* rtpeptr; if (rtpeitr == m_rtpool.end()) { routingtableentry* routeentryptr = m_nlsr.getroutingtable() .findroutingtableentry(destrouter); if (routeentryptr == nullptr) { routingtablepoolentry rtpe(destrouter); } else { routingtablepoolentry rtpe(*routeentryptr); } routingtablepoolentry* rtpeptr = addrtpetopool(rtpe); } else { routingtablepoolentry* rtpeptr = &(rtpeitr->second); } dosomestuffwithrtpe()
edit: here real code. error still variable scope? realize in example was, still problem here? tried conditional initialization of form: routingtablepoolentry rtpe(routeentryptr == nullptr? ... : ...);
didn't seem cooperate either.
edit #2: i'm idiot, excuse me. reason abundantly clear , wasn't seeing it.
rtpe = routingtablepoolentry(destrouter)
, rtpeptr = &(rtpeitr->second)
in slim chance makes gaff, too.
each object declared in statements following if , else has scope of these statements. after if-else statement object not visible , alive.
Comments
Post a Comment