Topic: Are elements of a vector required to have the '<' operator defined?
Author: "Sean Shubin" <sean.shubin@integtech.com>
Date: 1998/10/11 Raw View
At the risk of going off the topic, here is my workaround for MicroSoft
compilers:
#ifdef _MSC_VER
bool operator <(const MyClass& left,const MyClass& right);
bool operator==(const MyClass& left,const MyClass& right);
bool operator >(const MyClass& left,const MyClass& right);
bool operator<=(const MyClass& left,const MyClass& right);
bool operator!=(const MyClass& left,const MyClass& right);
bool operator>=(const MyClass& left,const MyClass& right);
#endif
Sean Shubin <sean.shubin@integtech.com> wrote in article
<01bdf2fb$8c5844b0$ae6dd7ce@srs>...
> The following code works fine in Borland compilers, but generates an
error
> in MicroSoft compilers. Which complier is compliant with the standard in
> this particular case?
>
> #include <vector>
>
> class MyClass{};
>
> int
> main(int argc,char** argv)
> {
> std::vector<MyClass> x;
> return 0;
> }
>
> //Borland: works fine.
> //Microsoft: gives error message "xutility(45) : error C2678: binary '<'
:
> no operator defined which takes a left-hand operand of type 'const class
> MyClass' (or there is no acceptable conversion)".
>
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sean Shubin" <sean.shubin@integtech.com>
Date: 1998/10/11 Raw View
The following code works fine in Borland compilers, but generates an error
in MicroSoft compilers. Can anyone tell me which complier is compliant
with the standard in this particular case?
#include <vector>
class MyClass{};
int
main(int argc,char** argv)
{
std::vector<MyClass> x;
return 0;
}
Borland: works fine.
Microsoft: gives error message "xutility(45) : error C2678: binary '<' :no
operator defined which takes a left-hand operand of type 'const class
MyClass' (or there is no acceptable conversion)".
If I add these lines after the definition of MyClass, both compilers are
happy.
#ifdef _MSC_VER
bool operator <(const MyClass& left,const MyClass& right);
bool operator==(const MyClass& left,const MyClass& right);
bool operator >(const MyClass& left,const MyClass& right);
bool operator<=(const MyClass& left,const MyClass& right);
bool operator!=(const MyClass& left,const MyClass& right);
bool operator>=(const MyClass& left,const MyClass& right);
#endif
My apologies if this get posted twice, my newsgroup program is giving me a
hard time.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Bo Persson <bop@malmo.mail.telia.com>
Date: 1998/10/12 Raw View
Sean Shubin wrote:
>
> The following code works fine in Borland compilers, but generates an error
> in MicroSoft compilers. Which complier is compliant with the standard in
> this particular case?
>
> #include <vector>
>
> class MyClass{};
>
> int
> main(int argc,char** argv)
> {
> std::vector<MyClass> x;
> return 0;
> }
>
> //Borland: works fine.
> //Microsoft: gives error message "xutility(45) : error C2678: binary '<' :
> no operator defined which takes a left-hand operand of type 'const class
> MyClass' (or there is no acceptable conversion)".
>
Works fine with MSVC version 6.0 !
Bo Persson
bop@malmo.mail.telia.com
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1998/10/12 Raw View
Sean Shubin wrote:
>
> The following code works fine in Borland compilers, but generates an
> error in MicroSoft compilers. Which complier is compliant with the
> standard in this particular case?
>
> #include <vector>
>
> class MyClass{};
>
> int
> main(int argc,char** argv)
> {
> std::vector<MyClass> x;
> return 0;
> }
>
> gives error message "xutility(45): error C2678: binary '<' :
> no operator defined which takes a left-hand operand of type 'const
> class MyClass' (or there is no acceptable conversion)".
This looks like the sort of error that cropped up with earlier
implementations of templates, where the compiler would check the
semantics of an entire template class, including all member function
definitions, when the class is instantiated. According to 14.7.1, that's
not allowed any more, and only the declarations of unused member
functions are supposed to be instantiated, not their definitions.
--
Ciao,
Paul
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/10/12 Raw View
In article <01bdf2fb$8c5844b0$ae6dd7ce@srs>, sean.shubin@integtech.com
says...
>
> The following code works fine in Borland compilers, but generates an error
> in MicroSoft compilers. Which complier is compliant with the standard in
> this particular case?
[ sample using: class MyClass{}; std::vector<MyClass> elided ]
Older versions of MS' compiler had a problem with this because they
expanded template functions even if they were never used. With
reasonably current versions of the compiler (VC++ 5.0 SP3, VC++ 6.0)
this problem no longer exists.
--
Later,
Jerry.
The Universe is a figment of its own imagination.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sean Shubin" <sean.shubin@integtech.com>
Date: 1998/10/09 Raw View
The following code works fine in Borland compilers, but generates an error
in MicroSoft compilers. Which complier is compliant with the standard in
this particular case?
#include <vector>
class MyClass{};
int
main(int argc,char** argv)
{
std::vector<MyClass> x;
return 0;
}
//Borland: works fine.
//Microsoft: gives error message "xutility(45) : error C2678: binary '<' :
no operator defined which takes a left-hand operand of type 'const class
MyClass' (or there is no acceptable conversion)".
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Edward Diener <eddielee@abraxis.com>
Date: 1998/10/10 Raw View
{ Quoted banners removed. Please check your quoting. -jep }
The '<' operator does not have to be defined in this case. Borland is
compliant and Microsoft is not. I believe this may have been fixed by MS in
one of their fixpaks to VC++ 5.0 or in 6.0.
Sean Shubin wrote:
> The following code works fine in Borland compilers, but generates an error
> in MicroSoft compilers. Which complier is compliant with the standard in
> this particular case?
> #include <vector>
>
> class MyClass{};
> int
> main(int argc,char** argv)
> {
> std::vector<MyClass> x;
> return 0;
> }
> //Borland: works fine.
> //Microsoft: gives error message "xutility(45) : error C2678: binary '<' :
> no operator defined which takes a left-hand operand of type 'const class
> MyClass' (or there is no acceptable conversion)".
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]