0
//Constructing set of all Places in Conflict with 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 the two lists are 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 is saying: "Unused variable p", though I am using it in the third for loop. In case further information is required, please leave a comment.

But this is something weird I am facing.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Gaurav Kalra
  • 281
  • 1
  • 2
  • 14
  • 3
    You might want to split this up into functions, at the least... – GManNickG Jul 23 '10 at 23:03
  • 1
    If you have a C++0x compatible compiler, consider using the auto keyword to make your loop initializers a little easier to read: http://en.wikipedia.org/wiki/C++0x#Type_inference – kenm Jul 23 '10 at 23:17

2 Answers2

4

You declared a completely different variable p in the inner loop. Here

for(SP_ListNode::const_iterator iterplaces = m_placeNodes->begin(),p=0; ...

The above is equivalent to declaring

SP_ListNode::const_iterator p = 0

which, of course, hides the outer p. The outer p remains unused, which is what the compiler is warning you about.

By a coincidence, this inner p is initializable with 0 and is comparable to int, even though its type is SP_ListNode::const_iterator, which is why there is no errors reported when you do this. But it is just a coincidence.

P.S. Just noticed that you did the same thing with all these outer int variables, which explains why the comparisons like p == l_placeVec do not fail.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • If i do it this way int p; for(SP_ListNode::const_iterator iterplaces = m_placeNodes->begin(),p=0; ... ... even then p is hidden. and i can't use multiple datatype declarations in for loop too. what is the way out then ? – Gaurav Kalra Jul 23 '10 at 23:06
  • @Gaurav: You initialize it prior to the `for`. *Of course* moving the `p` doesn't change the result, the first statement in a for-loop is a declaration, regardless of anything outside the loop. That first statement, as is, will always make a new variable named `p`, now and forever. – GManNickG Jul 23 '10 at 23:07
  • @Gaurav Kalra: Stop redeclaring `p`. Either do `p = 0` *before* the cycle, or declare `SP_ListNode::const_iterator iterplaces` before the cycle. In the latter case the cycle will look as follows: `for(iterplaces = m_placeNodes->begin(),p=0;...`. – AnT stands with Russia Jul 23 '10 at 23:08
  • @Gaurav not true. In C++ you can: http://stackoverflow.com/questions/75538/hidden-features-of-c/889001#889001 – Johannes Schaub - litb Jul 23 '10 at 23:11
0

"SP_ListNode::const_iterator iterplaces = m_placeNodes->begin(),p=0;" creates a new p of type SP_ListNode::const_iterator...so the outer p is not used.

Ryan
  • 26
  • 3