Bonjour,
J'ai un probl�me concernant l'h�ritage.
En effet, je d�sire avoir une classe GEometric Shape virtuelle et 2 sous classes Ellipse et Polygon.
J'ai cr�e cette classe virtuelle pour pouvoir utiliser ce type g�n�rique par ailleurs. par exemple j'aimerai pouvoir avoir un vecteur de GeometricShape dans une autre classe.
Voici le code de mes classes :
Classe GeometricShape :
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 #ifndef GEOMETRICSHAPE_HPP_ #define GEOMETRICSHAPE_HPP_ #include "Point.h" #include <vector> using namespace std; namespace sys{ class GeometricShape { public: GeometricShape(); GeometricShape(const GeometricShape& gs){}; GeometricShape& operator=(const GeometricShape& gs){} ; virtual vector<Point*> getPointsList() const = 0 ; virtual void setPointsList(vector<Point*> vec) = 0 ; virtual ~GeometricShape(){}; }; } #endif
Classe Polygon :
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 #ifndef POLYGON_HPP_ #define POLYGON_HPP_ #include "GeometricShape.h" using namespace std; namespace sys{ class Polygon : public GeometricShape { public: Polygon(void); Polygon(const Polygon& p); Polygon(vector<Point*> vec); Polygon& operator=(const Polygon& p); ~Polygon(void); void add(Point* p); Point& operator[](const int i); int getNbPoints() const; vector<Point*> getPointsList() const; void setPointsList(vector<Point*> vec); private : vector<Point*> _pointsList; }; } #endif
Classe Ellipse :
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 #ifndef ELLIPSE_HPP_ #define ELLIPSE_HPP_ #include "GeometricShape.h" namespace sys{ class Ellipse : public GeometricShape { public: Ellipse(void); Ellipse(Point* center, Point* width, Point* height); Ellipse(Point* center, Point* radius); // only for a center Ellipse(const Ellipse& ellipse); Ellipse& operator=(const Ellipse& e); ~Ellipse(void); Point* getWidth(); Point* getHeight(); Point* getCenter(); vector<Point*> getPointsList() const; void setPointsList(vector<Point*> vec); private : Point* _center; Point* _width; // largeur Point* _height; // hauteur }; } #endif
Quand je veux utiliser un attribut Geometric Shape dans une autre classe, j'ai l'erreur suivante :
Object.h:18: error: cannot declare parameter `pos' to be of type `sys::Geometric
Shape'
Object.h:18: error: because the following virtual functions are abstract:
GeometricShape.h:17: error: virtual void sys::GeometricShape::setPointsList(std
::vector<sys:: Point*, std::allocator<sys:: Point*> >)
extrait de ma classe Object :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8 class Object { .... protected : int _id; GeometricShape _position; };
Partager