C++ variable scope error inside for loop -


//constructing set of places in conflict each other int l_placevec, l_placevec1,p; for(sp_listlistnode::const_iterator iter = m_posttransitionsset.begin(),l_placevec=0; iter != m_posttransitionsset.end(); iter++,l_placevec++) {     for(sp_listlistnode::const_iterator inneriter = m_posttransitionsset.begin(),l_placevec1=0; inneriter != m_posttransitionsset.end(); inneriter++,l_placevec1++) {         if((iter != inneriter) && ((**inneriter) == (**iter)) && (((int)((*iter)->size()))>1)) { //when 2 lists same             sp_listnode* temper = new sp_listnode;             temper->clear();             for(sp_listnode::const_iterator iterplaces = m_placenodes->begin(),p=0; iterplaces != m_placenodes->end(); iterplaces++,p++) {                 if((p == l_placevec) || (p == l_placevec1)) {                     temper->push_back(*iterplaces);                 }             }             m_conflictingplaces.push_back(temper);         }     } } 

the above code saying: "unused variable p", though using in third loop. in case further information required, please leave comment.

but weird facing.

you declared different variable p in inner loop. here

for(sp_listnode::const_iterator iterplaces = m_placenodes->begin(),p=0; ... 

the above equivalent declaring

sp_listnode::const_iterator p = 0 

which, of course, hides outer p. outer p remains unused, compiler warning about.

by coincidence, inner p initializable 0 , comparable int, though type sp_listnode::const_iterator, why there no errors reported when this. coincidence.

p.s. noticed did same thing all these outer int variables, explains why comparisons p == l_placevec not fail.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -