Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Constructor called while accessing vector

Name: Anonymous 2007-07-05 4:10 ID:gbn8N62F

I have a vector of a class of units:
std::vector<Unit> Units; //list of units

In Unit the constructor Unit::Unit() has a boolean value 'selected'. calling .select sets it to true

but for some reason when i go through each unit in the vector:

for(int i=0;i < Units.size(); i++){
    Units.at(i).select(driver,images);
}

it resets all values as if it got created again, with selected turning false. but
unit.select();

select does change inside the function, but not in the class. why would it do that?

Name: Anonymous 2007-07-05 4:14 ID:gbn8N62F

Bah, i solved it. not worth time writing.

Those interested it was because in my for loop of selecting:

for(int i=0;i < Units.size(); i++){
                    Unit strd = Units.at(i);
                    if(strd.hitTest((unsigned int)dragStartX,(unsigned int)dragStartY,(unsigned int)dragToX,(unsigned int)dragToY)){
                        strd .select();
                    }else{
                        strd .unselect();
                    }
                }

created a new pointer to the object, thus treating it like a new class.

changing strd to Units.at(i) made it point to the unit itself, not the the new pointer

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List