Operator = pour mon vector<POINT>
Bonjour,
Mon problème est le suivant :
J'ai déclarer une classe CCurve dans lequel j'ai un membre m_PointList étant une liste de points déclarer comme ça :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
class CCurve :: CElement
{
protected:
vector<POINT> m_PointList; // Type safe point list
public:
virtual void Draw(HDC hdc, const CElement* pElement = 0) const;
...
} |
dans la fonction Draw de CCurve, je souhaite parcours les elements de ma list ou de mon vector à l'aide d'un iterator Si je met ce code dans mon fonction Draw, ça compile sans probleme :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
vector<POINT> the_vector;
vector<POINT>::iterator the_iterator;
POINT xy;
xy.x=0;
xy.y=1;
for( int i=0; i < 10; i++ ) the_vector.push_back(xy);
the_iterator = the_vector.begin();
while( the_iterator != the_vector.end() )
++the_iterator; |
par contre ça, si je fais appel à vector ou ma list membre
Code:
1 2 3 4
|
vector<POINT>::iterator aPoz;
aPoz = this->m_PointList.begin(); |
mais en compilant, voila ce que le compilateur me sort :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| 1>c:\users\administrator\desktop\developpement\cpp\exemple\elements.cpp(243) : error C2679: '=' binaire : aucun opérateur trouvé qui accepte un opérande de partie droite de type 'std::_Vector_const_iterator<_Ty,_Alloc>' (ou il n'existe pas de conversion acceptable)
1> with
1> [
1> _Ty=POINT,
1> _Alloc=std::allocator<POINT>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(405): peut être 'std::_Vector_iterator<_Ty,_Alloc> &std::_Vector_iterator<_Ty,_Alloc>::operator =(const std::_Vector_iterator<_Ty,_Alloc> &)'
1> with
1> [
1> _Ty=POINT,
1> _Alloc=std::allocator<POINT>
1> ]
1> lors de la tentative de mise en correspondance de la liste des arguments '(std::_Vector_iterator<_Ty,_Alloc>, std::_Vector_const_iterator<_Ty,_Alloc>)'
1> with
1> [
1> _Ty=POINT,
1> _Alloc=std::allocator<POINT>
1> ] |
Je pensai que c'étais un probleme de surcharge d'opérator, le "=". j'ai essayé de le définir dans la class parents, CElement...
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
|
class CElement
{
protected:
COLORREF m_Color; // Color of an element
RECT m_EnclosingRect; // Rectangle enclosing an element
int m_Pen; // Pen width
POINT m_Center;
public:
virtual ~CElement(){} ; // Virtual destructor
CElement (const CElement & );
// Virtual draw operation
virtual void Draw(HDC hdc, const CElement* pElement = 0) const {};
virtual void Move(const SIZE& Size) {}; // Move an element
RECT GetBoundRect() const; // Get the bounding rectangle for an element
CElement &operator =(vector<CElement>::iterator aElement)
{
m_Color = aElement->m_Color;
m_EnclosingRect = aElement->m_EnclosingRect;
m_Pen = aElement->m_Pen;
m_Center.x = aElement->m_Center.x;
// by convention, always return *this
return *this;
}
CElement &operator =(const CElement &aElement)
{ // swap this with other
if(this!=&aElement)
{
m_Color = aElement.m_Color;
m_EnclosingRect = aElement.m_EnclosingRect;
m_Pen = aElement.m_Pen;
m_Center = aElement.m_Center;
}
// by convention, always return *this
return *this;
}
protected:
CElement(){} ; // Default constructor
}; |
S'il vous plais, je cherche absolument à utiliser un moyen pour stoqué mes (structure) points, je peine...
Merci pour votre aide