Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2360 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  [RESOLU] vtable error

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[RESOLU] vtable error

n°2035796
karlakir
Posté le 13-11-2010 à 16:56:26  profilanswer
 

Salut,
 
j'ai une erreur (vous l'aurez deviné) en lien avec d'apres ce que j'ai lu, les destructeurs virtuelles.
 
pour resumer les codes:
j'ai une fonction:
- point
- graphical object qui est une classe abstraite qui include point
- differentes figures classe publique de graphical object (ex class cercle: public graphicalobject)
- une classe group qui contient 50 obj graph
 
avant que j'ajoute la classe group, tout marchait bien
depuis, j'ai une erreur vtable
 
voici les differents codes:
 
point.cpp

Code :
  1. #include "Point.hpp"
  2. Point Point::ORIGINE(0,0);
  3. Point::~Point() {}
  4. double Point::dist(Point& a, Point& b)
  5. {
  6.     return sqrt((a._x-b._x)*(a._x-b._x)+(a._y-b._y)*(a._y-b._y));
  7. }
  8. std::string Point::tostring()
  9. {
  10.   std::string chaine("un point:\n" );
  11.   std::ostringstream ossx;
  12.   std::ostringstream ossy;
  13.   ossx << _x;
  14.   ossy << _y;
  15.   chaine += "x = "+ossx.str()+"\n"+"y = "+ossy.str()+"\n";
  16.  
  17.   return chaine;
  18. }
  19. void Point::display()
  20. {
  21.   std::cout << this->tostring() << std::endl;
  22. }


 
point.hpp

Code :
  1. #include <iostream>
  2. #include <math.h>
  3. #include <sstream>
  4. class Point
  5. {
  6.     private:
  7.         int _x;
  8.         int _y;
  9.     public:
  10. static Point ORIGINE;
  11. Point():_x(0),_y(0) {};
  12.         Point(int inx, int iny): _x(inx),_y(iny) {};
  13.         ~Point();
  14.         int getx() const {return _x;}
  15.         int gety() const {return _y;}
  16. void setPoint(int inx, int iny) {_x=inx,_y=iny;}
  17. void setx(int inx) {_x=inx;}
  18. void sety(int iny) {_y=iny;}
  19.         static double dist(Point& a, Point& b);
  20. std::string tostring();
  21. void display();
  22. };


 
GraphicalObject.hpp

Code :
  1. #ifndef GraphicalObject_HPP
  2. #define GraphicalObject_HPP
  3. #include <iostream>
  4. #include "Point.hpp"
  5. typedef enum COLORS
  6. {
  7.     rouge,
  8.     vert,
  9.     bleu
  10. }COLORS;
  11. class GraphicalObject
  12. {
  13.     private:
  14.         static int _cpt_id; //compteur
  15.         int _id;
  16.         Point _origin;
  17.         int _width;
  18.         int _height;
  19.         COLORS _couleurs;
  20.        
  21.   public:
  22.     GraphicalObject();
  23.     GraphicalObject(Point inp, int inwidth, int inheight);
  24.     virtual ~GraphicalObject() {_cpt_id--;};
  25.    
  26.     void setorigin(Point inp) {_origin=inp;}
  27.     void setwidth(int inwidth) {_width=inwidth;}
  28.     void setheight(int inheight) {_height=inheight;}
  29.     void setcolor(COLORS incoul) {_couleurs=incoul;}
  30.    
  31.     int getid() {return _id;};
  32.     Point getorigin() {return _origin;};
  33.     int getwidth() {return _width;};
  34.     int getheight() {return _height;};
  35.     COLORS getcolors() {return _couleurs;};
  36.    
  37.     virtual std::string tostring() = 0;
  38.     virtual void display() = 0;
  39. };
  40. #endif


 
GraphicalObject.cpp

Code :
  1. #include "GraphicalObject.hpp"
  2. int GraphicalObject::_cpt_id = 0;
  3. GraphicalObject::GraphicalObject()
  4. {
  5.   _cpt_id +=1;
  6.  
  7.   _id = _cpt_id;
  8.   _origin=Point::ORIGINE;
  9.   _width = 0;
  10.   _height = 0;
  11.   _couleurs = vert;
  12. }
  13. GraphicalObject::GraphicalObject(Point inp, int inwidth, int inheight)
  14. {
  15.   _cpt_id +=1;
  16.  
  17.   _id = _cpt_id;
  18.   _origin = inp;
  19.   _width = inwidth;
  20.   _height = inheight;
  21.   _couleurs = vert;
  22. }


 
Cercle.hpp

Code :
  1. #ifndef Cercle_HPP
  2. #define Cercle_HPP
  3. #include "GraphicalObject.hpp"
  4. class Cercle: public GraphicalObject
  5. {
  6.   public:
  7.     void display();
  8.     std::string tostring();
  9. };
  10. #endif


 
Cercle.cpp

Code :
  1. #include "Cercle.hpp"
  2. std::string Cercle::tostring()
  3. {
  4.   std::string chaine("cercle:\n" );
  5.   std::ostringstream ossx;
  6.   std::ostringstream ossy;
  7.   std::ostringstream ossh;
  8.   std::ostringstream ossid;
  9.  
  10.   ossx << getorigin().getx();
  11.   ossy << getorigin().gety();
  12.   ossh << getheight();
  13.   ossid << getid();
  14.   chaine += "id: "+ossid.str()+"\n"+"x: "+ossx.str()+"\n"+"y: "+ossy.str()+"\n";
  15.   chaine += "rayon: "+ossh.str()+"\n";
  16.  
  17.   return chaine;
  18. }
  19. void Cercle::display()
  20. {
  21.   std::cout << this->tostring() << std::endl;
  22. }


 
Group.hpp

Code :
  1. #ifndef Group_HPP
  2. #define Group_HPP
  3. #include "GraphicalObject.hpp"
  4. class Group: public GraphicalObject
  5. {
  6.  
  7.     private:
  8.       GraphicalObject * _list[50];
  9.       int _compt;
  10.      
  11.     public:
  12.       Group();
  13.       virtual ~Group() {};
  14.      
  15.       bool attach(GraphicalObject *pOG);
  16.       void detach(GraphicalObject *pOG);
  17.      
  18.       void display();
  19.       std::string tostring();
  20.      
  21. };
  22. #endif


 
Group.cpp

Code :
  1. #include "Group.hpp"
  2. Group::Group()
  3. {
  4. for(int i=0;i<50;i++) _list[i]=0;
  5. _compt = 0;
  6. }
  7. bool Group::attach(GraphicalObject * pOG)
  8. {
  9.   int res =0;
  10.   if(_compt<50)
  11.   {
  12.     int i=0;
  13.     while(_list[i]!=0) i++;
  14.     _list[i] = pOG;
  15.     _compt++;
  16.    
  17.     Point temp(std::min(getorigin().getx(), pOG->getorigin().getx()),
  18.       std::min(getorigin().gety(), pOG->getorigin().gety()));
  19.     setorigin(temp);
  20.    
  21.     setwidth(std::max(getwidth(), getorigin().getx()+pOG->getwidth()));
  22.     setheight(std::max(getheight(), getorigin().gety()+pOG->getheight()));
  23.    
  24.     res=1;
  25.   }
  26.   return res;
  27. }
  28. void Group::detach(GraphicalObject * pOG)
  29. { }


 
Erreur

Code :
  1. g++ -Wall -ansi -pedantic -Wextra   Cercle.o GraphicalObject.o Group.o line.o main.o Point.o Rectangle.o -lm -o ./exe
  2. Group.o: In function `Group::Group()':
  3. Group.cpp:(.text+0x16): undefined reference to `vtable for Group'
  4. Group.o: In function `Group::Group()':
  5. Group.cpp:(.text+0x68): undefined reference to `vtable for Group'
  6. main.o: In function `Group::~Group()':
  7. main.cpp:(.text._ZN5GroupD1Ev[Group::~Group()]+0xb): undefined reference to `vtable for Group'
  8. collect2: ld returned 1 exit status
  9. make: *** [pMed] Erreur 1


 
voila, (et sinon, le code doit pas etre génial, je debute :D )
 
merci d'avance


Message édité par karlakir le 15-11-2010 à 21:08:36

---------------
Si vous avez rien à faire, cliquez ici:
mood
Publicité
Posté le 13-11-2010 à 16:56:26  profilanswer
 

n°2035799
Un Program​meur
Posté le 13-11-2010 à 17:18:19  profilanswer
 

Ton seul membre virtuel de Group (le destructeur) est inline et il y a des chaînes de développement qui n'aiment pas ça.


---------------
The truth is rarely pure and never simple (Oscar Wilde)
n°2035803
karlakir
Posté le 13-11-2010 à 18:04:56  profilanswer
 

ca marche!!
 
merci beaucoup!
 
donc plus de destructeur virtuel inline si j'ai bien compris?


---------------
Si vous avez rien à faire, cliquez ici:
n°2035807
Un Program​meur
Posté le 13-11-2010 à 18:23:07  profilanswer
 

Le problème c'est de ne pas avoir de membre virtuel non inline.


---------------
The truth is rarely pure and never simple (Oscar Wilde)
n°2035868
karlakir
Posté le 14-11-2010 à 14:22:55  profilanswer
 

Je comprend pas,
 
je dois avoir au moins un membre virtuel non inline et puis je peux mettre tous les autre inline ?
 
j'ai vraiment du mal avec les notions d heritage et les methodes virtuelles (bref le concept objet :) )


---------------
Si vous avez rien à faire, cliquez ici:
n°2035881
Un Program​meur
Posté le 14-11-2010 à 17:26:31  profilanswer
 

karlakir a écrit :

Je comprend pas,
 
je dois avoir au moins un membre virtuel non inline et puis je peux mettre tous les autre inline ?


 
Oui.
 

Citation :

j'ai vraiment du mal avec les notions d heritage et les methodes virtuelles (bref le concept objet :) )


 
Ceci n'est en rien conceptuel, c'est juste une limitation d'un certain nombre de compilateurs.  Je ne pense pas que la norme l'impose (j'ai jamais cherché).


---------------
The truth is rarely pure and never simple (Oscar Wilde)
n°2036131
karlakir
Posté le 15-11-2010 à 21:07:48  profilanswer
 

oki!!
 
merci beaucoup pour ton aide  
 
 
(et je te dis à bientot, ainsi qu'à toute la communauté, I Will Be Back!!! c'est sur :) )


---------------
Si vous avez rien à faire, cliquez ici:

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  [RESOLU] vtable error

 

Sujets relatifs
Fatal error: Cannot instantiate non-existent class: sqlitedatabaseVC++: cl.exe error C2275: Mais pourquoi ????
[Ada+C] Storage Error à la lecture d'une entrée Midi en C via Adarésoudre : Notice: unserialize() [function.unserialize]: Error at offs
Got Error 12 from table handlerError - Java / Persistance
Link error et Objective-C[Ada][Résolut] Error Vertex_Not_In_Graph à l'ajout d'un arc.
Error Parse PHP ... :-( WikimediaXML parsing error
Plus de sujets relatifs à : [RESOLU] vtable error


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR