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.
Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21