Quote:
Originally Posted by Barnabé
tabVertex[ligne] = new Vertex ( etiq , degre, x,y );
tu fais une affectation, je ne comprend pas pourquoi il y a une allocation dynamique avant ton appel de fonction, en gros je ne comprend pourquoi il y a un new , alors que tu as alloué l'espace précédemment :
Vertex *tabVertex = new Vertex[getNbreVert()];
En meme temps j'ai un peu perdu en C++ donc ... si je comprend plus tout, c'est un peu normal, sinon une bonne solution, si tu ne trouves pas, tu décomposes jusqu'a trouver ou ca coince :
tu alloues la memoire de ton tableau
tu affectes a une variable
puis tu remplis ton tableau par la variable.
tabVertex[ligne] = Vertex ( etiq , degre, x,y ) ne marche-t-il pas ?
|
ouais t'as raison apparemment ya pas besoin de new
en même temps quand je l'enlève j'ai une erreur:
main.cc: In function `void Read_Graph(char*, AdjList&, HashTable&, int)':
main.cc:186: error: no match for 'operator=' in '*(tabVertex + (+(ligne * 2

)) = Vertex(etiq, degre, x, y)'
vertex.h:61: error: candidates are: void Vertex:

perator=(Vertex&)
main.cc:239: error: cannot convert `Vertex' to `Vertex*' for argument `1' to `float distanceE(Vertex*, Vertex*)'
main.cc:242: error: cannot convert `Vertex' to `Vertex*' for argument `1' to `float distanceE(Vertex*, Vertex*)'
make: *** [main.o] Erreur 1
apparemment il va chercher un operateur = redefini dans Vertex.h
--
void operator =(Vertex& b) {
= b.name;
parent = b.parent;
distance = b.distance;
degre = b.degre;
x=b.x;
y=b.y;
};
--
que penses tu de ces lignes ?
Vertex **tabVertex = new Vertex*[getNbreVert()];
tabVertex[ligne] = new Vertex ( etiq , degre, x,y );
ou alors je dois retirer la redefinition de l'operator =