Parcours d'une liste de structure
memedplay
Messages postés
4
Date d'inscription
Statut
Membre
Dernière intervention
-
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Char Snipeur Messages postés 9813 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
J'essaie de faire une fonction qui parcoure une list de Noeud, classe qui ne fait pas partie de la STL mais que je creer.
J'ai un problème à la compilation :
noeud.cc:122:49: erreur: conversion from `std::list<Noeud>::const_iterator {aka std::_List_const_iterator<Noeud>}' to non-scalar type `std::list<Noeud>::iterator {aka std::_List_iterator<Noeud>}' requested
Voici le code de la classe :
#include <iostream>
#include <string>
#include <list>
#include <map>
#include "noeud.h"
#include "noeudtexte.h"
using namespace std;
/* Constructeurs */
Noeud::Noeud(){
nom= "noeud inconnu";
indentation = 0;
pere = NULL;
lignedeb = NULL;
lignefin = NULL;
facteurDeb = NULL;
facteurFin = NULL;
}
Noeud::Noeud(string name, int ind, Noeud &father, Ligne &LD, Ligne &LF, Facteur &FD, Facteur &FF){
nom= name;
indentation = ind;
pere = &father;
lignedeb = &LD;
lignefin = &LF;
facteurDeb = &FD;
facteurFin = &FF;
}
Noeud::Noeud(const Noeud& noeudcopie){
nom= noeudcopie.nom;
indentation = noeudcopie.indentation;
pere = noeudcopie.pere;
lignedeb = noeudcopie.lignedeb;
lignefin = noeudcopie.lignefin;
facteurDeb = noeudcopie.facteurDeb;
facteurFin = noeudcopie.facteurFin;
}
/* Destructeur */
Noeud::~Noeud(){}
/* Accesseurs */
string Noeud::getNom() const{
return nom;
}
void Noeud::setNom(string _nom){
nom = _nom;
}
Noeud Noeud::getPere() const{
return pere;
}
Noeud Noeud::setPere(Noeud &N){
pere = N
}
int Noeud::getIndent() const{
return indentation;
}
void Noeud::setIndent(int i){
indentation = i;
}
Ligne* Noeud::getLigneDeb() const{
return lignedeb;
}
void Noeud::setLigneDeb(Ligne LD){
lignedeb = &LD;
}
Ligne* Noeud::getLigneFin() const{
return lignefin;
}
void Noeud::setLigneFin(Ligne LF){
lignefin = &LF;
}
Facteur* Noeud::getFacteurDeb() const{
return facteurDeb;
}
void Noeud::setFacteurDeb(Facteur FD){
facteurDeb = &FD;
}
Facteur* Noeud::getFacteurFin() const{
return facteurFin;
}
void Noeud::setFacteurFin(Facteur FF){
facteurFin = &FF;
}
/* Méthodes pour modifier le noeud */
void Noeud::ajoutAttribut(string att){
listeAttributs.push_back(att);
}
void Noeud::ajoutfils(const Noeud N){
descendant.push_back(N);
N.setPere(this);
N.setIndent(indentation + 1);
}
bool Noeud::presentfils(const Noeud& N) const{ // vérifie si un noeud est présent dans la liste des fils du noeud courant
if(descendant.empty()){
return false;
}
else{
list<Noeud>::iterator it = descendant.begin();
while(it != descendant.end()){
if((*it) == N){
return true;
}
it++;
}
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(*it.presentfils(N)){
return true;
}
}
}
return false;
}
bool Noeud::supprimeAttribut(string &att){
for (list<string>::iterator it = listeAttributs.begin() ; it != listeAttributs.end(); ++it){
if(*it == att){
listeAttributs.erase(it);
return true;
}
}
return false;
}
/* Méthode d'affichage */
// virtual istream& saisie(istream&);
ostream& Noeud::affiche(ostream &os) const{
for(int i =0 ; i < indentation ; i++){
os << '\t';
}
os << nom << endl;
if(!descendant.empty()){
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
*it.affiche(&os);
}
}
return os;
}
/* Méthode de calcul */
int Noeud::nbAttribut() const{
if(listeAttributs.empty()){
return 0;
}
return listeAttributs.size();
}
int Noeud::nbFils() const{
if(descendant.empty()){
return 0;
}
return descendant.size();
}
int Noeud::indent() const{
return indentation;
}
/* Méthode d'accès au fils */
list<Noeud> Noeud::retournerNodesFils(){
return descendant;
}
list<Noeud> Noeud::retournerTextFils(){
list<Noeudtexte> textfils;
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(typeid(it) == typeid(Noeudtexte)){
textfils.push_back(&it);
}
}
return textfils;
}
/* Surcharge d'opérateur */
bool Noeud::operator==(const Noeud &N) const{
if(nom == N.nom && indentation == N.indentation && pere == N.pere && lignedeb == N.lignedeb &&
lignefin == N.lignefin && facteurDeb == N.facteurDeb && facteurFin == N.facteurFin){
if(descendant.size() == N.descendant.size()){
list<Noeud>::iterator itN = N.descendant.begin();
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(it == itN){
++itN;
}
else return false;
}
}
if(listeAttributs.size() == N.listeAttributs.size()){
list<Noeud>::iterator itN = N.listeAttributs.begin();
for (list<Noeud>::iterator it = listeAttributs.begin() ; it != listeAttributs.end(); ++it){
if(it == itN){
++itN;
}
else return false;
}
}
return true;
}
return false;
}
/* Surcharge de Flots */
ostream& operator<< (ostream &os, const Noeud &node){
node.affiche(os);
return os;
}
//istream& operator>> (istream&, Noeud&);
Je ne comprend pas d'où peut venir l'erreur sur les 2 ligne en gras, sachant que ça fonctionne si je prend une list de int ou string.
Est-ce que quelqu'un aurait une idée du problème?
J'essaie de faire une fonction qui parcoure une list de Noeud, classe qui ne fait pas partie de la STL mais que je creer.
J'ai un problème à la compilation :
noeud.cc:122:49: erreur: conversion from `std::list<Noeud>::const_iterator {aka std::_List_const_iterator<Noeud>}' to non-scalar type `std::list<Noeud>::iterator {aka std::_List_iterator<Noeud>}' requested
Voici le code de la classe :
#include <iostream>
#include <string>
#include <list>
#include <map>
#include "noeud.h"
#include "noeudtexte.h"
using namespace std;
/* Constructeurs */
Noeud::Noeud(){
nom= "noeud inconnu";
indentation = 0;
pere = NULL;
lignedeb = NULL;
lignefin = NULL;
facteurDeb = NULL;
facteurFin = NULL;
}
Noeud::Noeud(string name, int ind, Noeud &father, Ligne &LD, Ligne &LF, Facteur &FD, Facteur &FF){
nom= name;
indentation = ind;
pere = &father;
lignedeb = &LD;
lignefin = &LF;
facteurDeb = &FD;
facteurFin = &FF;
}
Noeud::Noeud(const Noeud& noeudcopie){
nom= noeudcopie.nom;
indentation = noeudcopie.indentation;
pere = noeudcopie.pere;
lignedeb = noeudcopie.lignedeb;
lignefin = noeudcopie.lignefin;
facteurDeb = noeudcopie.facteurDeb;
facteurFin = noeudcopie.facteurFin;
}
/* Destructeur */
Noeud::~Noeud(){}
/* Accesseurs */
string Noeud::getNom() const{
return nom;
}
void Noeud::setNom(string _nom){
nom = _nom;
}
Noeud Noeud::getPere() const{
return pere;
}
Noeud Noeud::setPere(Noeud &N){
pere = N
}
int Noeud::getIndent() const{
return indentation;
}
void Noeud::setIndent(int i){
indentation = i;
}
Ligne* Noeud::getLigneDeb() const{
return lignedeb;
}
void Noeud::setLigneDeb(Ligne LD){
lignedeb = &LD;
}
Ligne* Noeud::getLigneFin() const{
return lignefin;
}
void Noeud::setLigneFin(Ligne LF){
lignefin = &LF;
}
Facteur* Noeud::getFacteurDeb() const{
return facteurDeb;
}
void Noeud::setFacteurDeb(Facteur FD){
facteurDeb = &FD;
}
Facteur* Noeud::getFacteurFin() const{
return facteurFin;
}
void Noeud::setFacteurFin(Facteur FF){
facteurFin = &FF;
}
/* Méthodes pour modifier le noeud */
void Noeud::ajoutAttribut(string att){
listeAttributs.push_back(att);
}
void Noeud::ajoutfils(const Noeud N){
descendant.push_back(N);
N.setPere(this);
N.setIndent(indentation + 1);
}
bool Noeud::presentfils(const Noeud& N) const{ // vérifie si un noeud est présent dans la liste des fils du noeud courant
if(descendant.empty()){
return false;
}
else{
list<Noeud>::iterator it = descendant.begin();
while(it != descendant.end()){
if((*it) == N){
return true;
}
it++;
}
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(*it.presentfils(N)){
return true;
}
}
}
return false;
}
bool Noeud::supprimeAttribut(string &att){
for (list<string>::iterator it = listeAttributs.begin() ; it != listeAttributs.end(); ++it){
if(*it == att){
listeAttributs.erase(it);
return true;
}
}
return false;
}
/* Méthode d'affichage */
// virtual istream& saisie(istream&);
ostream& Noeud::affiche(ostream &os) const{
for(int i =0 ; i < indentation ; i++){
os << '\t';
}
os << nom << endl;
if(!descendant.empty()){
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
*it.affiche(&os);
}
}
return os;
}
/* Méthode de calcul */
int Noeud::nbAttribut() const{
if(listeAttributs.empty()){
return 0;
}
return listeAttributs.size();
}
int Noeud::nbFils() const{
if(descendant.empty()){
return 0;
}
return descendant.size();
}
int Noeud::indent() const{
return indentation;
}
/* Méthode d'accès au fils */
list<Noeud> Noeud::retournerNodesFils(){
return descendant;
}
list<Noeud> Noeud::retournerTextFils(){
list<Noeudtexte> textfils;
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(typeid(it) == typeid(Noeudtexte)){
textfils.push_back(&it);
}
}
return textfils;
}
/* Surcharge d'opérateur */
bool Noeud::operator==(const Noeud &N) const{
if(nom == N.nom && indentation == N.indentation && pere == N.pere && lignedeb == N.lignedeb &&
lignefin == N.lignefin && facteurDeb == N.facteurDeb && facteurFin == N.facteurFin){
if(descendant.size() == N.descendant.size()){
list<Noeud>::iterator itN = N.descendant.begin();
for (list<Noeud>::iterator it = descendant.begin() ; it != descendant.end(); ++it){
if(it == itN){
++itN;
}
else return false;
}
}
if(listeAttributs.size() == N.listeAttributs.size()){
list<Noeud>::iterator itN = N.listeAttributs.begin();
for (list<Noeud>::iterator it = listeAttributs.begin() ; it != listeAttributs.end(); ++it){
if(it == itN){
++itN;
}
else return false;
}
}
return true;
}
return false;
}
/* Surcharge de Flots */
ostream& operator<< (ostream &os, const Noeud &node){
node.affiche(os);
return os;
}
//istream& operator>> (istream&, Noeud&);
Je ne comprend pas d'où peut venir l'erreur sur les 2 ligne en gras, sachant que ça fonctionne si je prend une list de int ou string.
Est-ce que quelqu'un aurait une idée du problème?
A voir également:
- Parcours d'une liste de structure
- Liste déroulante excel - Guide
- Liste déroulante en cascade - Guide
- Liste code ascii - Guide
- Logiciel calcul structure bois gratuit - Télécharger - Architecture & Déco
- Liste de diffusion whatsapp - Guide