widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #04128
Re: coding question (pointers, upcasting ....)
-
To:
widelands-dev@xxxxxxxxxxxxxxxxxxx
-
From:
Fòram na Gàidhlig <fios@xxxxxxxxxxxxxxxxxxx>
-
Date:
Thu, 25 Jun 2015 15:48:07 +0200
-
In-reply-to:
<CAGCtC0BPv3rn9=BebUT8WX5+4hP81b6e8ftV_oxDdmEuhe0qsw@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
Upcast does not change the const/pointer/reference types, just the class
type. From this code snippet, I can't tell where the const or & comes from.
Sgrìobh Tibor Bamhor na leanas 25/06/2015 aig 14:36:
> 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
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~widelands-dev
> Post to : widelands-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~widelands-dev
> More help : https://help.launchpad.net/ListHelp
>
>
>
> E-Mail ist virenfrei.
> Von AVG überprüft - www.avg.de <http://www.avg.de>
> Version: 2015.0.6037 / Virendatenbank: 4365/10094 - Ausgabedatum:
> 25.06.2015
>
--
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.22 (MingW32)
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