J'ai une fonction qui retourne une list qui ne doit pas être modifiée :
const list<Robot*>& make_team( );
La liste est constante, mais les robots ne le sont pas (?)
je récupère cette liste et la passe en argument à une autre fonction qui
fait l'union de toutes les equipes :
void
RobotController::add_robots_in_game( const list<Robot*>& robot_list ) {
list<Robot*>::iterator li;
for( li = robot_list.begin(); li != robot_list.end(); li ++ )
all_robots_in_game.push_back( *li );
}
Je recois l'erreur suivante :
conversion from
`std::_List_iterator<Robot*, Robot* const&, Robot* const*>'
to non-scalar type
`std::_List_iterator<Robot*, Robot*&, Robot**>' requested
Où est l'erreur ? où doivent se placer les const ? ...
--------------------------------------------
Benoît Rousseau : roussebe at spray dot se
Jouez en programmant : http://realtimebattle.sourceforge.net/
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Benoit Dejean
Le Sat, 25 Oct 2003 12:33:17 +0200, Benoit Rousseau a écrit :
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); }
Je recois l'erreur suivante : conversion from `std::_List_iterator<Robot*, Robot* const&, Robot* const*>' to non-scalar type `std::_List_iterator<Robot*, Robot*&, Robot**>' requested
Où est l'erreur ? où doivent se placer les const ? ...
list<Robot*>::const_iterator li;
Le Sat, 25 Oct 2003 12:33:17 +0200, Benoit Rousseau a écrit :
void
RobotController::add_robots_in_game( const list<Robot*>& robot_list ) {
list<Robot*>::iterator li;
for( li = robot_list.begin(); li != robot_list.end(); li ++ )
all_robots_in_game.push_back( *li );
}
Je recois l'erreur suivante :
conversion from
`std::_List_iterator<Robot*, Robot* const&, Robot* const*>' to
non-scalar type
`std::_List_iterator<Robot*, Robot*&, Robot**>' requested
Où est l'erreur ? où doivent se placer les const ? ...
Le Sat, 25 Oct 2003 12:33:17 +0200, Benoit Rousseau a écrit :
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); }
Je recois l'erreur suivante : conversion from `std::_List_iterator<Robot*, Robot* const&, Robot* const*>' to non-scalar type `std::_List_iterator<Robot*, Robot*&, Robot**>' requested
Où est l'erreur ? où doivent se placer les const ? ...
list<Robot*>::const_iterator li;
Ivan Vecerina
"Benoit Dejean" wrote in message news:
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); } ...
list<Robot*>::const_iterator li;
Correct. Ceci dit, la fonction pourrait s'écrire plus simplement: all_robots_in_game.insert( all_robots_in_game.end() robot_list.begin(), robot_list.end() ); ou: std::copy( robot_list.begin(), robot_list.end() , std::back_inserter( all_robots_in_game ) );
Suggestion utile, je l'espère... Ivan -- http://ivan.vecerina.com http://www.brainbench.com <> Brainbench MVP for C++
"Benoit Dejean" <bnet@ifrance.com> wrote in message
news:pan.2003.10.25.10.33.42.280505@ifrance.com...
void
RobotController::add_robots_in_game( const list<Robot*>& robot_list ) {
list<Robot*>::iterator li;
for( li = robot_list.begin(); li != robot_list.end(); li ++ )
all_robots_in_game.push_back( *li );
}
...
list<Robot*>::const_iterator li;
Correct.
Ceci dit, la fonction pourrait s'écrire plus simplement:
all_robots_in_game.insert( all_robots_in_game.end()
robot_list.begin(), robot_list.end() );
ou:
std::copy( robot_list.begin(), robot_list.end()
, std::back_inserter( all_robots_in_game ) );
Suggestion utile, je l'espère...
Ivan
--
http://ivan.vecerina.com
http://www.brainbench.com <> Brainbench MVP for C++
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); } ...
list<Robot*>::const_iterator li;
Correct. Ceci dit, la fonction pourrait s'écrire plus simplement: all_robots_in_game.insert( all_robots_in_game.end() robot_list.begin(), robot_list.end() ); ou: std::copy( robot_list.begin(), robot_list.end() , std::back_inserter( all_robots_in_game ) );
Suggestion utile, je l'espère... Ivan -- http://ivan.vecerina.com http://www.brainbench.com <> Brainbench MVP for C++
Benoit Rousseau
Ivan Vecerina wrote:
"Benoit Dejean" wrote in message
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); } list<Robot*>::const_iterator li;
Correct. Ceci dit, la fonction pourrait s'écrire plus simplement: all_robots_in_game.insert( all_robots_in_game.end() robot_list.begin(), robot_list.end() ); ou: std::copy( robot_list.begin(), robot_list.end() , std::back_inserter( all_robots_in_game ) ); Suggestion utile, je l'espère...
Oui, c'est en effet plus joli...
-- -------------------------------------------- Benoît Rousseau : roussebe at spray dot se Jouez en programmant : http://realtimebattle.sourceforge.net/
Ivan Vecerina wrote:
"Benoit Dejean" <bnet@ifrance.com> wrote in message
void
RobotController::add_robots_in_game( const list<Robot*>& robot_list ) {
list<Robot*>::iterator li;
for( li = robot_list.begin(); li != robot_list.end(); li ++ )
all_robots_in_game.push_back( *li );
}
list<Robot*>::const_iterator li;
Correct.
Ceci dit, la fonction pourrait s'écrire plus simplement:
all_robots_in_game.insert( all_robots_in_game.end()
robot_list.begin(), robot_list.end() );
ou:
std::copy( robot_list.begin(), robot_list.end()
, std::back_inserter( all_robots_in_game ) );
Suggestion utile, je l'espère...
Oui, c'est en effet plus joli...
--
--------------------------------------------
Benoît Rousseau : roussebe at spray dot se
Jouez en programmant : http://realtimebattle.sourceforge.net/
void RobotController::add_robots_in_game( const list<Robot*>& robot_list ) { list<Robot*>::iterator li; for( li = robot_list.begin(); li != robot_list.end(); li ++ ) all_robots_in_game.push_back( *li ); } list<Robot*>::const_iterator li;
Correct. Ceci dit, la fonction pourrait s'écrire plus simplement: all_robots_in_game.insert( all_robots_in_game.end() robot_list.begin(), robot_list.end() ); ou: std::copy( robot_list.begin(), robot_list.end() , std::back_inserter( all_robots_in_game ) ); Suggestion utile, je l'espère...
Oui, c'est en effet plus joli...
-- -------------------------------------------- Benoît Rousseau : roussebe at spray dot se Jouez en programmant : http://realtimebattle.sourceforge.net/
Benoit Dejean
Le Sun, 26 Oct 2003 02:08:07 +0200, Ivan Vecerina a écrit :
"Benoit Dejean" wrote in message
list<Robot*>::const_iterator li;
Correct. Ceci dit, la fonction pourrait s'écrire plus simplement: all_robots_in_game.insert ou: std::copy(... std::back_inserter );
Suggestion utile, je l'espère...
certes ça m'apprendra à flemmarder :oD
Le Sun, 26 Oct 2003 02:08:07 +0200, Ivan Vecerina a écrit :
"Benoit Dejean" <bnet@ifrance.com> wrote in message
list<Robot*>::const_iterator li;
Correct.
Ceci dit, la fonction pourrait s'écrire plus simplement:
all_robots_in_game.insert
ou:
std::copy(... std::back_inserter );