Voila, je programme des arbres avec héritage et template.

La classe "AbstractTree" est héritée par "ListTree" et "VectorTree". ListTree utilise des noeuds, un structure qui contient des pointeur ver les fils (gauche et droit).

Voici AbstractTree.h :
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
#ifndef __ABSTRACT_TREE_HPP
#define __ABSTRACT_TREE_HPP
 
#include <iostream>
#include "Node.h"
using namespace std;
 
class AbstractTree
{
    public:
     virtual void insert(Node) = 0;
     virtual anElement racine() const = 0;
     virtual bool vide() const = 0;
};
 
#endif
Voici Node.h :
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
23
#ifndef __NODE_HPP
#define __NODE_HPP
 
#include <iostream>
using namespace std;
 
template <class anElement>
class Node
{
    private:
     Node* leftSon, rightSon;
     anElement value;
 
    public:
     Node(anElement aValue)         {leftSon=NULL; rightSon=NULL; value = aValue;};
     Node* getLeftSon() const       {return leftSon;};
     Node* getRightSon() const      {return rightSon;};
     void setLeftSon(Node* aNode)   {leftSon = aNode;};
     void setRightSon(Node* aNode)  {rightSon = aNode;};
     anElement getValue() const     {return value;};
};
 
#endif
Voici le ListTree.h :
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
#ifndef __LIST_TREE_HPP
#define __LIST_TREE_HPP
 
#include <iostream>
#include "AbstractTree.h"
using namespace std;
 
 
class ListTree : public AbstractTree
{
    public:
     ListTree();
     bool vide() const;
     bool operator==(const Node) const;
     Node racine() const;
     void insert(const Node);
};
 
#endif
Il me dit, lors de la compilation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
AbstractTree.h:11: error: `Node' is not a type
AbstractTree.h:11: error: ISO C++ forbids declaration of `parameter' with no type
AbstractTree.h:12: error: `anElement' does not name a type
ListTree.h:14: error: ISO C++ forbids declaration of `Node' with no type
ListTree.h:15: error: `Node' does not name a type
ListTree.h:16: error: ISO C++ forbids declaration of `Node' with no type
:: === Build finished: 6 errors, 0 warnings ===
J'ai essayé avec un autre compilteur, on ne sait jamais, mais sans résultat...
Aidez-moi svp ! Merci d'avance !