Le_Berurier | Bonjour,
J'ai un petit problème de compilation.
Si quelqu'un pouvait m'aider.
J'ai une classe A ou je définis les operateurs =, <, >, <=, >=, ==
Dans une autre classe B, je définis un vecteur de A, Code :
- std::vector<A> vect;
|
Le problème se trouve quand j'utilise la fonction de tri de <algorithm> :
Code :
- std::sort(vect.begin(), vect.end());
|
J'obtiens alors le message d'erreur suivant :
Code :
- ------ Build started: Project: MainEngine, Configuration: Debug Win32 ------
- Compiling...
- main.cpp
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2623) : error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const A' (or there is no acceptable conversion)
- A.h(14): could be 'A &A::operator =(A)'
- while trying to match the argument list '(const A, A)'
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2639) : see reference to function template instantiation 'void std::_Insertion_sort1<_BidIt,A>(_BidIt,_BidIt,_Ty *)' being compiled
- with
- [
- _BidIt=std::_Vector_const_iterator<A,std::allocator<A>>,
- _Ty=A
- ]
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2747) : see reference to function template instantiation 'void std::_Insertion_sort<_RanIt>(_BidIt,_BidIt)' being compiled
- with
- [
- _RanIt=std::_Vector_const_iterator<A,std::allocator<A>>,
- _BidIt=std::_Vector_const_iterator<A,std::allocator<A>>
- ]
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2754) : see reference to function template instantiation 'void std::_Sort<std::_Vector_const_iterator<_Ty,_Alloc>,__w64 int>(_RanIt,_RanIt,_Diff)' being compiled
- with
- [
- _Ty=A,
- _Alloc=std::allocator<A>,
- _RanIt=std::_Vector_const_iterator<A,std::allocator<A>>,
- _Diff=__w64 int
- ]
- main.cpp(24) : see reference to function template instantiation 'void std::sort<std::_Vector_const_iterator<_Ty,_Alloc>>(_RanIt,_RanIt)' being compiled
- with
- [
- _Ty=A,
- _Alloc=std::allocator<A>,
- _RanIt=std::_Vector_const_iterator<A,std::allocator<A>>
- ]
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2630) : error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const A' (or there is no acceptable conversion)
- A.h(14): could be 'A &A::operator =(A)'
- while trying to match the argument list '(const A, const A)'
- d:\appli\microsoft visual studio 8\vc\include\algorithm(2631) : error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const A' (or there is no acceptable conversion)
- A.h(14): could be 'A &A::operator =(A)'
- while trying to match the argument list '(const A, A)'
- Build log was saved at "file://BuildLog.htm"
- MainEngine - 3 error(s), 0 warning(s)
- ======== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
J'ai bien défini l'operator=
Code :
- A& operator = (const A& a);
|
Je comprends pas pourquoi le compilo attend 2 arguments (const A& lhs, A rhs) ???
Merci de votre aide.
|