Initialisation de classe Membre
Bonjour je suis débutant en C++ et j'ai un petit probleme :
Code:
1 2 3 4 5 6 7 8
|
edge.cpp: In constructor Edge::Edge(const Vertex&, const Vertex&):
edge.cpp:8: erreur: no matching function for call to Vertex::Vertex()
../include/vertex.hpp:8: note: candidats sont: Vertex::Vertex(float, float, float)
../include/vertex.hpp:4: note: Vertex::Vertex(const Vertex&)
edge.cpp:8: erreur: no matching function for call to Vertex::Vertex()
../include/vertex.hpp:8: note: candidats sont: Vertex::Vertex(float, float, float)
../include/vertex.hpp:4: note: Vertex::Vertex(const Vertex&) |
J'image que cela est un problème d'initialisation de mes membre _v1 et _v2. Je vous passe 4 fichier de mon code vertex.cpp et vertex.hpp qui st en fait des points avec les coordonnées en 3 dimensions et edge.cpp et edge.hpp qui sont des arretes reliant certains de ces points.
vertex.hpp
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
|
#ifndef VERTEX_HPP
#define VERTEX_HPP
class Vertex {
public:
// Constructeur
Vertex (float x, float y, float z);
// Accesseur en lecture seulement
float x () const;
float y () const;
float z () const;
private:
float _x, _y, _z;
};
// Opérateur de comparaison
bool operator== (const Vertex &v1, const Vertex &v2);
bool operator!= (const Vertex &v1, const Vertex &v2);
bool operator> (const Vertex &v1, const Vertex &v2);
bool operator<= (const Vertex &v1, const Vertex &v2);
bool operator< (const Vertex &v1, const Vertex &v2);
bool operator>= (const Vertex &v1, const Vertex &v2);
#endif /* VERTEX_HPP */ |
vertex.cpp
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
|
#include "vertex.hpp"
/*
Constructeur :
*/
Vertex::Vertex (float x, float y, float z) {
this->_x = x;
this->_y = y;
this->_z = z;
}
/*
Accesseur :
en lecture seulement
*/
float Vertex::x () const {
return _x;
}
float Vertex::y () const {
return _y;
}
float Vertex::z () const {
return _z;
}
/*
Opérateur :
*/
bool operator== (const Vertex &v1, const Vertex &v2) {
return ((v1.x() == v2.x()) &&
(v1.y() == v2.y()) &&
(v1.z() == v2.z()));
}
bool operator!= (const Vertex &v1, const Vertex &v2) {
return (!(v1 == v2));
}
bool operator> (const Vertex &v1, const Vertex &v2) {
if (v1.x() > v2.x())
return true;
else if (v1.x() < v2.x())
return false;
if (v1.y() > v2.y())
return true;
else if (v1.y() < v2.y())
return false;
if (v1.z() > v2.z())
return true;
else if (v1.z() < v2.z())
return false;
return false;
}
bool operator<= (const Vertex &v1, const Vertex &v2) {
return (!(v1 > v2));
}
bool operator< (const Vertex &v1, const Vertex &v2) {
if (v2.x() > v1.x())
return true;
else if (v2.x() < v1.x())
return false;
if (v2.y() > v1.y())
return true;
else if (v2.y() < v1.y())
return false;
if (v2.z() > v1.z())
return true;
else if (v2.z() < v1.z())
return false;
return false;
}
bool operator>= (const Vertex &v1, const Vertex &v2) {
return (!(v1 < v2));
} |
edge.hpp
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
|
#ifndef EDGE_HPP
#define EDGE_HPP
#include "vertex.hpp"
class Edge {
public:
// Constructeur
Edge (const Vertex &v1, const Vertex &v2);
// Accesseur en lecture seulement
Vertex point1 () const;
Vertex point2 () const;
private:
Vertex _v1;
Vertex _v2;
};
// Opérateur de comparaison
bool operator== (const Edge &e1, const Edge &e2);
bool operator!= (const Edge &e1, const Edge &e2);
bool operator> (const Edge &e1, const Edge &e2);
bool operator<= (const Edge &e1, const Edge &e2);
bool operator< (const Edge &e1, const Edge &e2);
bool operator>= (const Edge &e1, const Edge &e2);
#endif /* EDGE_HPP*/ |
edge.cpp
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
|
#include "edge.hpp"
#include "vertex.hpp"
/*
Constructeur :
*/
Edge::Edge (const Vertex &v1, const Vertex &v2) {
if (v1 < v2) {
_v1 = v1;
_v2 = v2;
}
else {
_v1 = v1;
_v2 = v2;
}
}
/*
Accesseur :
*/
Vertex Edge::point1 () const {
return _v1;
}
Vertex Edge::point2 () const {
return _v2;
}
/*
Opérateurs :
*/
bool operator== (const Edge &e1, const Edge &e2) {
return ((e1.point1() == e2.point1()) &&
(e1.point2() == e2.point2()));
}
bool operator!= (const Edge &e1, const Edge &e2) {
return (!(e1 == e2));
} |
Voila, j'aimerai evidemment que la fonction Edge::point1() renvoie vraiment le vetex correspondant de tel manière à que si on le midifie ca modifie celuiqui était passer en argument dans le constructeur de Edge.
Merci d'avance si quelqu'un peut m'expliquer rapidement ou si quelqu'un à un exemple de code analogue à l'utilisation que je veux faire de mes classes.