Bonjour,
Je ne parviens pas � faire en sorte que mon main reconnaisse les appels � la classe V3.
Voici mon code:
main.cpp
V3.hpp:
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <iostream> #include "V3.hpp" using namespace std; int main() { V3 u(2.1,5.3,6.4); cout << u << endl; V3 v; cout << u << endl; return 0; }
V3.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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #ifndef V3_HPP_INCLUDED #define V3_HPP_INCLUDED #include <iostream> class V3 { private: float x; float y; float z; public: V3(); V3(float _x, float _y, float _z); V3(const V3& v); virtual ~V3(); V3& operator=(const V3& v); V3& operator+(const V3& v); float getX(); float getY(); float getZ(); void setX(float _x); void setY(float _y); void setZ(float _z); V3& operator+=(const V3& v); bool isNull(); }; bool operator==(const V3& u, const V3& v); float operator%(const V3& u, const V3& v); V3 operator^ (const V3& u, const V3& v); bool operator||(const V3& u, const V3& v); std::ostream& operator<<(std::ostream& os, const V3& v); #endif // V3_HPP_INCLUDED
Je re�oit autant d'erreurs 'undefined reference to' que j'ai d'appels � la classe V3 dans le main.
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
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 #include "V3.hpp" using namespace std; V3::V3() { this->x = 0; this->y = 0; this->z = 0; } V3::V3(float _x, float _y, float _z): this->x(_x), this->y(_y), this->z(_z) {} V3::V3(const V3& v) { this->x = v.x; this->y = v.y; this->z = v.z; } V3::~V3() {} V3& V3::operator=(const V3& v) { this->x = v.x; this->y = v.y; this->z = v.z; return *this; } V3& V3::operator+(const V3& v) { this->x += v.x; this->y += v.y; this->z += v.z; return *this; } V3& V3::operator+=(const V3& u) { (*this) = (*this)+u; return *this; } float V3::getX() { return this->x; } float V3::getY() { return this->y; } float V3::getZ() { return this->z; } void V3::setX(float _x) { this->x = _x; } void V3::setY(float _y) { this->y = _y; } void V3::setZ(float _z) { this->z = _z; } bool V3::isNull() { return (this->x==0 && this->y==0 && this->z==0); } bool operator==(const V3& u, const V3& v) { return (u.getX() == v.getX() && u.getY() == v.getY() && u.getZ() == v.getZ()); } float operator%(const V3& u, const V3& v) { return (u.getX()*v.getX() + u.getY()*v.getY() + u.getZ()*v.getZ()); } V3 operator^(const V3& u, const V3& v) { V3 w; w.setX(u.getY()*v.getZ() - u.getZ()*v.getY()); w.setY(u.getX()*v.getZ() - u.getZ()*v.getX()); w.setZ(u.getX()*v.getY() - u.getX()*v.getY()); return w; } bool operator||(const V3& u, const V3& v) { return (u^v).isNull(); } ostream& operator<<(ostream& os, const V3& v) { os << "Vecteur:" << endl << "x: " << v.getX() << endl << "y: " << v.getY() << endl << "z: " << z.getZ() << endl; return os; }
J'ai d�ja eu cette erreur auparavant, elle s'�tait r�solue en mettant tout le code de V3 dans V3.cpp sans passer par un header, cela fonctionnait je ne sais pourquoi.
Je vous remercie d'avance pour toute r�ponse.
Ben
Partager