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.

2
  • 3
    You might want to split this up into functions, at the least... Commented Jul 23, 2010 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: en.wikipedia.org/wiki/C++0x#Type_inference Commented Jul 23, 2010 at 23:17

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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: 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.
@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;....
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.