Function being executed partially

Hey guys, i am new to this forum so pardon me if there are any mistakes in my question or if i am at wrong section.

So, i am making this complex kind of project where i have to deal with wingdi graphics, mainly FillRect(). What i am doing is, i am creating many rectangles with FillRect() and saving all of those in a vector array named elements. Now, each of these elements has a function sticked to it (through its class) and when i am iterating through those elements, i am able to execute the function bound to that element. But the problem is, when iterating through all elements EXCEPT last one, the bound function executes partially while only at LAST element, the bound function executes completely. That's weird, there is no runtime error or whatnot but this thing is bothering me for weeks. Here is a code-like example (not exactly what i am actually doing);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vector<myclass> elements;
int index = -1;

myclass::myclass() // constructor for creating elements
{
    FillRect(dc, MyRECT, RGB(255, 255, 255)); // dc is console handler, MyRECT is RECT structure of current element, color is while
    elements.push_back(*this);
}

void Navigate() // function to navigate through elements
{
    index++;
    try { elements.at(index).CustomFunction(); } // Executes custom function
    catch(out_of_range o) { }
}

void myclass::CustomFunction()
{
    cout << "executed!"; // This line is executed for all the elements
    FillRect(dc, MyRECT, RGB(255, 0, 0)); // This line does execute for all of rectangles but changes color of only LAST rectangle
}


I hope you guys understand. I can explain in more details if required.
Last edited on
Somehow it's not really clear what you want to do.
i am creating many rectangles with FillRect()

FillRect doesn't create a rectangle it draws a rectangle on the screen.

Why don't you use a normal for loop in your navigate function?

Can you show us the complete code.
Well the code itself is very complex i won't be able to explain here. I'll try writing a shorter version and explain it to you later.
Topic archived. No new replies allowed.