none
error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const double'

    Question

  •  

    Hi, if I compile my project with microsoft Visual studio 2003 works, but if I try to compile with microsoft visual studio 2005 I can't compile, this is the code:

     

    Code Snippet

    parceles(float xa,float xb,double vG,double vGA):x(xa),z(xb),valorGris(vG),valorGrisAcumulat(vGA)

    {}

    friend bool operator<(const parceles& esq, const parceles &dret){

    return esq.valorGrisAcumulat > dret.valorGrisAcumulat;

    }

    friend bool operator<(const parceles& esq, const double dret){

    return esq.valorGrisAcumulat < dret;

    }

     

     

     

    and this is the error:

     

     

    C:\Archivos de programa\Microsoft Visual Studio 8\VC\include\xutility(267) : error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const double' (or there is no acceptable conversion)

    1> c:\buscantnom\wxwidgets-2.8.7\samples\jefes\distribuidorGotes.h(20): could be 'bool operator <(const distribuidorGotes::parceles &,const distribuidorGotes::parceles &)' [found using argument-dependent lookup]

    1> c:\buscantnom\wxwidgets-2.8.7\samples\jefes\distribuidorGotes.h(23): or 'bool operator <(const distribuidorGotes::parceles &,const double)' [found using argument-dependent lookup]

    1> while trying to match the argument list '(const double, distribuidorGotes::parceles)'

    1> C:\Archivos de programa\Microsoft Visual Studio 8\VC\include\algorithm(2268) : see reference to function template instantiation 'bool std::_Debug_lt<distribuidorGotes::parceles,_Ty>(_Ty1 &,const _Ty2 &,const wchar_t *,unsigned int)' being compiled

    1> with

    1> [

    1> _Ty=double,

    1> _Ty1=distribuidorGotes::parceles,

    1> _Ty2=double

    1> ]

    1> C:\Archivos de programa\Microsoft Visual Studio 8\VC\include\algorithm(2280) : see reference to function template instantiation '_FwdIt std::_Lower_bound<std::_Vector_iterator<_Ty,_Alloc>,double,__w64 int>(_FwdIt,_FwdIt,const double &,_Diff *)' being compiled

    1> with

    1> [

    1> _FwdIt=std::_Vector_iterator<distribuidorGotes::parceles,std::allocator<distribuidorGotes::parceles>>,

    1> _Ty=distribuidorGotes::parceles,

    1> _Alloc=std::allocator<distribuidorGotes::parceles>,

    1> _Diff=__w64 int

    1> ]

    1> .\distribuidorGotes.cpp(94) : see reference to function template instantiation '_FwdIt std::lower_bound<std::_Vector_iterator<_Ty,_Alloc>,double>(_FwdIt,_FwdIt,const double &)' being compiled

    1> with

    1> [

    1> _FwdIt=std::_Vector_iterator<distribuidorGotes::parceles,std::allocator<distribuidorGotes::parceles>>,

    1> _Ty=distribuidorGotes::parceles,

    1> _Alloc=std::allocator<distribuidorGotes::parceles>

    1> ]

     

     

     

    <std::_Vector_iterator<distribuidorGotes::parceles,std::allocator<std::_Vector_iterator<distribuidorGotes::parceles,std::allocator

    Can any help me please?

    </distribuidorGotes::parceles,std::allocator</std::_Vector_iterator</distribuidorGotes::parceles,std::allocator</std::_Vector_iterator
    Friday, February 29, 2008 1:10 AM

Answers

  • Maybe you need one more friend operator: "friend bool operator < (const double dret, const parcels & esq)"?

     

    Friday, February 29, 2008 1:07 PM

All replies

  •  

    Hi~

    I've tested your code.

    There is no errors.

    Reference this msdn page for error C2678.

    http://support.microsoft.com/kb/155164

     

    Bye~

    Friday, February 29, 2008 3:58 AM
  •  

    Hi, thanks for the reply. Yes I know that the code is good because if i test my code with mvs2003 I don't get any errors. But if I try to build with 2005 I have this error, why?Can any help me?Thanks.
    Friday, February 29, 2008 11:21 AM
  •  

    No, I mean that I've tested on VS 2005.

    It's worked.

     

     

    Friday, February 29, 2008 12:46 PM
  • Maybe you need one more friend operator: "friend bool operator < (const double dret, const parcels & esq)"?

     

    Friday, February 29, 2008 1:07 PM
  • Microsoft has been improving langauge compliance and VC 2005 is more compliant than VC 2003. So there is a good chance that VC 2003 allowed something that is not standard and that VC 2005 does not.

     

    So be sure to read the documentation of the C2678 error. Also look at the MSDN page that lists and describes "breaking changes". The error message seems to be saying that you need to qualify the members with the class that contain them. It is possible that that is the result of improved language complinace.

    Friday, February 29, 2008 7:12 PM
  •  

    Thanks for the reply. Now run. I have added this friend operator:

    friend bool operator < (const double dret, const parcels & esq)

    and now run. Thanks.

     

    Friday, February 29, 2008 8:27 PM