Click to See Complete Forum and Search --> : operator < with a "set"


Sophie
June 1st, 1999, 11:32 AM
I hope someone can shed some light on how I need to define this operator to compare.

I get this error:

:\program files\microsoft visual studio\vc98\include\functional(86) : error C2678: binary '&lt;' : no operator defined which takes a left-hand operand of type 'const class FileToCopy' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less&lt;class FileToCopy&gt;::operator ()(const class FileToCopy &,const class FileToCopy &) const'

class FileToCopy //I've create dmy operator in here
{
private:
File src;
File dst;

public:
FileToCopy( const File &src_, const File &dst_)
: src( src_), dst( dst_)
{
}
FileToCopy()
{
}

const File &GetSrc() const { return src; }
const File &GetDst() const { return dst; }
operator &lt; (const FileToCopy &listOfFilesToCopy);


};

If you require more infornmation please let me know.

Thank you in Advance

ChrisD
June 1st, 1999, 12:31 PM
The only thing I see that stands out is your operator &lt; declaration does not return a bool.

HTH,
chris

Sophie
June 1st, 1999, 01:09 PM
I've added the return boolean but I still get this error. I'm not exactly sure how this operator works. Shouldn't I be doing some logic in the operator function..Like a compare or something..


HELP!!!

c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2678: binary '&lt;' : no operator defined which takes a left-hand operand of type 'const class FileToCopy' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less&lt;class FileToCopy&gt;::operator ()(const class FileToCopy &,const class FileToCopy &) const'

// TEMPLATE STRUCT less
template&lt;class _Ty&gt;
struct less : binary_function&lt;_Ty, _Ty, bool&gt; {
bool operator()(const _Ty& _X, const _Ty& _Y) const
{return (_X &lt; _Y); }
};

This is where the error ends up.

Thanks

eperales
June 1st, 1999, 01:22 PM
two guesses:
1) try using CX::operator &lt;(const CX& x)const

or

2) try an external friend operator

bool operator &lt;(const CX& lhs, const CX& rhs);