widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #04126
coding question (pointers, upcasting ....)
Hi,
I am searching for near bobs and putting them to
std::vector<Bob *> own_nearby;
then iterate over it and if the bob is soldier (and meets some other
requirements) I need to put it to
std::vector<Soldier *> defending_soldiers;
The relevant part of code is:
for (Bob * own : own_nearby) {
if (upcast(Soldier, ownSoldier, own)) {
if (ownSoldier->is_defending()){
defending_soldiers.back(ownSoldier);
}
}
}
But it complains during compilation:
error: no matching function for call to 'std::vector<const
Widelands::Soldier*>::back(Widelands::Soldier* const&)'
defending_soldiers.back(ownSoldier);
If I understand it correctly (if at all :) ) the upcast is making const
from soldier... how to circumvent it? defending_soldiers vector is to be
shortliving, immediately forgotten....
Ideas? :)
Tibor
Follow ups