Merci bien, je verrais car là j'ai un petit problème pour les visiteurs. Il semblerait qu'il ne détecte pas les bon types ! Dans mes visiteurs pour faire upgrader/downgrader les caractéristiques c'est ma fonction avec deux templates de type différents qui match et pourtant typeid().name() me retourne le même type et le bon pourtant !
les visiteurs :
Code:
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 class charactPlusOperator : public boost::static_visitor<void> { public: // handle each types void operator()(unsigned int &x, unsigned int &y) const { x = (x + y); cout << " Uint: "<<x<<" + "<<y<<" !"; } void operator()(signed int &x, signed int &y) const { x = (x + y); cout << " Sint: "<<x<<" + "<<y<<" !"; } void operator()(bool &x, bool &y) const { x = (x & y); cout << " bool: "<<x<<" & "<<y<<" !"; } void operator()(string &x, string &y) const { x = (x + y); cout << " string: "<<x<<" + "<<y<<" !"; } void operator()(float &x, float &y) const { x = (x + y); cout << " float: "<<x<<" + "<<y<<" !"; } template <typename T> void operator()(T &x, T &y) const { x = y; cout << " same Template: "<<x<<" = "<<y<<" !"; } template <typename T, typename U> void operator()(T &x, U &y) const { x = x; cout << " error types mismatch ("<< typeid(T).name() << " vs "<<typeid(U).name()<<") !"; } template <typename T> void operator()(T &x) const { x = x; cout << " error one argv given !"; } }; class charactMinusOperator : public boost::static_visitor<void> { public: // handle each types void operator()(unsigned int &x, unsigned int &y) const { x = (x - y); cout << " U["<<x<<"] "; } void operator()(signed int &x, signed int &y) const { x = (x - y); cout << " S["<<x<<"] "; } void operator()(bool &x, bool &y) const { x = (x & y); cout << " B["<<x<<"] "; } void operator()(string &x, string &y) const { x = y; cout << " St["<<x<<"] "; } void operator()(float &x, float &y) const { x = (x - y); cout << " F["<<x<<"] "; } template <typename T> void operator()(T &x, T &y) const { x = y; cout << " ?["<<x<<"] "; } template <typename T, typename U> void operator()(T &x, U &y) const { x = x; cout << " error types mismatch ("<< typeid(T).name() << " vs "<<typeid(U).name()<<") !"; } template <typename T> void operator()(T &x) const { x = x; cout << " error one argv given !"; } }; class charactZeroOperator : public boost::static_visitor<void> { public: // handle each types void operator()(unsigned int &x, unsigned int &y) const { x = y; cout << " U["<<x<<"] "; } void operator()(signed int &x, signed int &y) const { x = y; cout << " S["<<x<<"] "; } void operator()(bool &x, bool &y) const { x = y; cout << " B["<<x<<"] "; } void operator()(string &x, string &y) const { x = y; cout << " St["<<x<<"] "; } void operator()(float &x, float &y) const { x = y; cout << " F["<<x<<"] "; } template <typename T> void operator()(T &x, T &y) const { x = y; cout << " ?["<<x<<"] "; } template <typename T, typename U> void operator()(T &x, U &y) const { x = x; cout << " error types mismatch ("<< typeid(T).name() << " vs "<<typeid(U).name()<<") !"; } template <typename T> void operator()(T &x) const { x = x; cout << " error one argv given !"; } };
Méthode de Characteristic appelée pour faire l'upgrade
Code:
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
29 Characteristic Characteristic::doOperator(string _currOp, const Characteristic &upgrader) { if (_currOp.empty()) return *this; cout << " Before: "<< value << "+"<< upgrader.value; if (_currOp == string("+")) { cout << " (+) "; boost::apply_visitor(charactPlusOperator(), value, upgrader.value); } else if (_currOp == string("-")) { cout << " (-) "; boost::apply_visitor(charactMinusOperator(), value, upgrader.value); } else if (_currOp == string("0")) { cout << " (0) "; boost::apply_visitor(charactZeroOperator(), value, upgrader.value); } else if (_currOp == string("-1")) { cout << " (0) "; // Do nothing } else { cout << " (/) "; // Do nothing } cout << " ; After: " << value << endl; return *this; }
L'output intéressant du programme :
Code:
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
29
30
31
32
33
34 /* doUpgrade() called aoeRangeCases addition: Before: 4+0 (+) error types mismatch (j vs j) ! ; After: 4 attackRate addition: Before: 5+0 (-) error types mismatch (j vs j) ! ; After: 5 attackType addition: Before: 3+3 (0) error types mismatch (10damageType vs 10damageType) ! ; After: 3 canMove addition: Before: 0+0 (0) error types mismatch (b vs b) ! ; After: 0 casesHeight addition: Before: 1+1 (0) error types mismatch (j vs j) ! ; After: 1 casesWidth addition: Before: 1+1 (0) error types mismatch (j vs j) ! ; After: 1 firePower addition: Before: 5+10 (+) error types mismatch (j vs j) ! ; After: 5 fireRangeCases addition: Before: 3+0 (+) error types mismatch (j vs j) ! ; After: 3 maxHp addition: Before: 35+5 (+) error types mismatch (j vs j) ! ; After: 35 moveRate addition: Before: 0+0 (-) error types mismatch (j vs j) ! ; After: 0 runnerFlags addition: Before: 1+1 (0) error types mismatch (17entityRunnerFlags vs 17entityRunnerFlags) ! ; After: 1 texture addition: Before: texture.xml+texture.xml (0) error types mismatch (Ss vs Ss) ! ; After: texture.xml tower addition: Before: 1+1 (0) error types mismatch (b vs b) ! ; After: 1 towerFlags addition: Before: 8+8 (0) error types mismatch (16entityTowerFlags vs 16entityTowerFlags) ! ; After: 8 upgrade addition: Before: 0+1 (0) ; After: 0 Upgrade complete (0) */
Puisque tout semble tomber dans deux types différents il forcément impossible d'affecter x avec y, le compilateur me renvoie des erreurs bien sûr ! Peut-être avez-vous une idée de pourquoi il fait l'autruche ? Car tout le reste du programme fonctionne très bien, les types sont correctes, on le voit bien avec typeid(T / U).name() c'est les mêmes !
Merci d'avance.