Salut � tout le monde !
J'esp�re qu'� vous pourrez me donner un coup de main avec un probl�me li� � recursivit� et aux m�thodes virtuelles.
J'ai une fonction virtuelle qui s'appelle inList et qui est d�clar� dans la classe de base qui s'appelle Product.
La m�thode inList est red�finie dans 2 classes d�riv�es de Product : CompositeProduct et BasicProduct.
CompositeProduct a une attribute "std::vector<Product *> _listProduct". Ainsi on peut former des arbres compos�s par des BasicProducts et CompositeProducts � condition qu'� la base de l'arbre se trouve une CompositeProduct.
La finalit� de la m�thode inList est de rep�rer si un produit se trouve dans l'arbre ou pas.
les declarations pour inList sont les suivantes :
Quand j'essaie de compiler, le compilateur me montre les erreurs suivantes :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 inList declaration on class Product (classe de base): virtual bool inList(const Product * &)=0; inList implementqtion on class CompositeProduct (qui hérite de Product): bool CompositeProduct::inList(const Product* &iProduct) { std::list<Product*>::iterator iter; if (iProduct==this) {return true;} else { for (iter=_productList.begin(); iter!=_productList.end(); iter++) inList(*iter); } } inList implementation on class BasicProduct (aussi elle hérite de Product): bool BasicProduct::inList(const Product* & iProduct) { if (iProduct==this) return true; else return false; }
error: no matching function for call to �CompositeProduct::inList(Product*&)�
note: candidates are: virtual bool CompositeProduct::inList(const Product*&)
error: no matching function for call to �CompositeProduct::inList(BasicProduct*&)�
note: candidates are: virtual bool CompositeProduct::inList(const Product*&)
Quelqu'un peut m'aider svp?
Quelqu'un a une id�e de ce qu'il faut que je fasse ?
Merci d'avance !
Partager