counting

I am trying to get uniqueID in the following segment of code to count how many times the if statement gets used, but all i get is a list of 1's. Any ideas??
1
2
3
4
5
6
7
8
9
10
if (is_tri == true) {
    //add the triangle to the list
    unsigned int uniqueID = 0;
    uniqueID++;
    cout<< uniqueID << " ";
    triangle d_tri(uniqueID, (*nodeVec[i]), (*nodeVec[j]), (*nodeVec[k]));
    ListElement *p = new triangle(d_tri);
    triList.AddElement(p);
    triList.OutList();  
}

line 3: you are initializing uniqueID to 0 every time condition is true. All you need to do is to declare uniqueID somewhere else or make it static:
1
2
3
4
5
6
7
8
9
10
if (is_tri == true) {
    //add the triangle to the list
    static unsigned int uniqueID = 0; // <----
    uniqueID++;
    cout<< uniqueID << " ";
    triangle d_tri(uniqueID, (*nodeVec[i]), (*nodeVec[j]), (*nodeVec[k]));
    ListElement *p = new triangle(d_tri);
    triList.AddElement(p);
    triList.OutList();  
}
Topic archived. No new replies allowed.