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.
<rt id="pwjBlLZ"><small id="pwjBlLZ"></small></rt>
<acronym id="pwjBlLZ"></acronym><rt id="pwjBlLZ"></rt>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
<acronym id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></acronym>
<option id="pwjBlLZ"></option>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym><acronym id="pwjBlLZ"></acronym>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
  • 6512882421 2018-04-19
  • 4659652420 2018-04-19
  • 2967832419 2018-04-19
  • 8339042418 2018-04-19
  • 8147112417 2018-04-19
  • 2774752416 2018-04-19
  • 4316132415 2018-04-19
  • 6265742414 2018-04-19
  • 1875142413 2018-04-19
  • 4146552412 2018-04-19
  • 8205662411 2018-04-19
  • 959982410 2018-04-19
  • 7153742409 2018-04-19
  • 9349932408 2018-04-18
  • 6024052407 2018-04-18
  • 2113432406 2018-04-18
  • 7629172405 2018-04-18
  • 163882404 2018-04-18
  • 3515922403 2018-04-18
  • 5047802402 2018-04-18