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);
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.