question de newbie je pense.
J'ai des classes LLGenotypeTreeLeaf, LLGenotypeTreeBinaryOperator, LLGenotypeTreeUnaryOperator, qui dérrivent de LLGenotypeTreeElement.
Je veux implanter dans chacune de ces classes la fonction "evaluate" qui varrira selon la classe.
Pour cela je déclare cette fonction en virtual dans LLGenotypeTreeElement et je la code dans les sous classes. Ca compilait jusqu'au jour où j'ai décidé de coder un constructeur dans une sous classe, et là il m'a mis :
unresolved external symbol "public: virtual float __thiscall LLGenotypeTreeElement::Evaluate(int,int,int)
Mon code est :
TreeElement.h : (pas de cpp correspondant)
TreeBinaryOperator.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 LLGENOTYPETREEELEMENT_H #define LLGENOTYPETREEELEMENT_H #include <stdlib.h> #include <math.h> #include <iostream> using namespace std; class LLGenotypeTreeElement { private : char _Type; unsigned int _Level; LLGenotypeTreeElement * _Parent; public : virtual float Evaluate(int X, int Y, int Z); char Type() {return _Type;}; }; #endif
TreeBinaryOperator.cpp :
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 #ifndef LLGENOTYPETREEBINARYOPERATOR_H #define LLGENOTYPETREEBINARYOPERATOR_H #include "LLGenotypeTreeElement.h" class LLGenotypeTreeBinaryOperator : public LLGenotypeTreeElement { private : LLGenotypeTreeElement * _Son1; LLGenotypeTreeElement * _Son2; public : LLGenotypeTreeBinaryOperator(); float Evaluate(int X, int Y, int Z); }; #endif
Je veux bien un coup de pouce pour savoir ce qui ne va pas et ce que je n'ai pas compris.
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
24
25
26
27
28 #include "LLGenotypeTreeBinaryOperator.h" LLGenotypeTreeBinaryOperator :: LLGenotypeTreeBinaryOperator() { _Son1 = NULL; _Son2 = NULL; } float LLGenotypeTreeBinaryOperator :: Evaluate(int X, int Y, int Z) { switch(Type()) { case '+' : return _Son1->Evaluate(X,Y,Z) + _Son2->Evaluate(X,Y,Z); break; case '-' : return _Son1->Evaluate(X,Y,Z) - _Son2->Evaluate(X,Y,Z); break; case '*' : return _Son1->Evaluate(X,Y,Z) * _Son2->Evaluate(X,Y,Z); break; case '/' : return _Son1->Evaluate(X,Y,Z) / _Son2->Evaluate(X,Y,Z); break; default : return 0.; } }
Partager